What is Git And Git Hub..??

What is Git And Git Hub..??

No alt text provided for this image

GitHub is a platform where you can host your code & can do version control in a dedicated or shared environment with your colleagues.

The “Git” in GitHub

To understand GitHub, you must first have an understanding of Git. Git is an open-source version control system that was started by Linus Torvalds—the same person who created Linux. Git is similar to other version control systems—Subversion, CVS, and Mercurial to name a few.

No alt text provided for this image

The “Hub” in GitHub

We’ve established that Git is a version control system, similar but better than the many alternatives available. So, what makes GitHub so special? Git is a command-line tool, but the center around which all things involving Git revolve is the hub—GitHub.com—where developers store their projects and network with like minded people.

Let’s go over a few of the main reasons that geeks like to use GitHub, and learn some terminology along the way.

No alt text provided for this image


Difference Between Git And GitHub

GitHub is a central repository and?cloud-based service?that allows developers to store and manage their code in the cloud, as well as track and control modifications.

Git is a free, open-source distributed?version control tool?that may be used for both small and big projects. Git was created to make it easier for programmers and developers to collaborate.

No alt text provided for this image

The Work Flow of GitHub

No alt text provided for this image

Cloud Based Hosting Services

Cloud hosting is a cloud delivery strategy that uses?Infrastructure as a Service (IaaS)?to provide a set of remote/virtual services. These services are provided on-demand and are hosted on a cloud computing infrastructure.?Full apps and development platforms, as well as servers, storage, and virtual desktops, are all available as cloud-based services.

No alt text provided for this image


What is a “version control system”??

Version control systems are a category of software tools that helps in recording changes made to files by keeping a track of modifications done to the code.

No alt text provided for this image

Why Version Control system is so Important?

As we know that a software product is developed in collaboration by a group of developers they might be located at different locations and each one of them contributes in some specific kind of functionality/features. So in order to contribute to the product, they made modifications in the source code(either by adding or removing). A version control system is a kind of software that helps the developer team to efficiently communicate and manage(track) all the changes that have been made to the source code along with the information like who made and what change has been made. A separate branch is created for every contributor who made the changes and the changes aren’t merged into the original source code unless all are analyzed as soon as the changes are green signalled they merged to the main source code. It not only keeps source code organized but also improves productivity by making the development process smooth.

Benefits of the version control system:

a)?Enhances the project development speed by providing efficient collaboration,

b)?Leverages the productivity, expedite product delivery, and skills of the employees through better communication and assistance,

c)?Reduce possibilities of errors and conflicts meanwhile project development through traceability to every small change,

d)?Employees or contributor of the project can contribute from anywhere irrespective of the different geographical locations through this?VCS,

e)?For each different contributor of the project a different working copy is maintained and not merged to the main file unless the working copy is validated. A most popular example is?Git, Helix core, Microsoft TFS,

f)?Helps in recovery in case of any disaster or contingent situation,

g)?Informs us about Who, What, When, Why changes have been made.

Forking a Repo

“Forking” is when you create a new project based off of another project that already exists. This is an amazing feature that vastly encourages the further development of programs and other projects. If you find a project on GitHub that you’d like to contribute to, you can fork the repo, make the changes you’d like, and release the revised project as a new repo. If the original repository that you forked to create your new project gets updated, you can easily add those updates to your current fork.

No alt text provided for this image

Social networking

The social networking aspect of GitHub is probably its most powerful feature, allowing projects to grow more than just about any of the other features offered. Each user on GitHub has their own profile that acts like a resume of sorts, showing your past work and contributions to other projects via pull requests.Project revisions can?be discussed publicly, so a mass of experts can contribute knowledge and collaborate to advance a project forward. Before the advent of GitHub, developers interested in contributing to a project would usually need to find some means of contacting the authors—probably by email—and then convince them that they can be trusted and their contribution is legit.

GitHub Isn’t Just for Developers

All this talk about how GitHub is ideal for programmers may have you believing that they are the only ones who will find it useful. Although it’s a lot less common, you can actually use GitHub for any types of files. If you have a team that is constantly making changes to a word document, for example,?you could use GitHub as your version control system. This practice isn’t common, since there are better alternatives in most cases, but it’s something to keep in mind.

What is Pulling And Pushing

No alt text provided for this image

Pull Requests

You’ve forked a repository, made a great revision to the project, and want it to be recognized by the original developers—maybe even included in the official project/repository. You can do so by creating a pull request. The authors of the original repository can see your work, and then choose whether or not to accept it into the official project. Whenever you issue a pull request, GitHub provides a perfect medium for you and the main project’s maintainer to communicate.

No alt text provided for this image

The git pull command downloads changes from a remote repository and saves them to a local repository. It combines changes from upstream into your local repository, which is a regular activity in Git-based collaborations. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.

$ git remote add origin <central repository's link>         

This command is used to make a central repository the origin.

$ git pull origin master        

This command will copy all files from the remote repository's master branch to your local repository.

$ git pull origin <branch-name>        

This command is used for pulling files from a different branch.

  • Now to make a new branch use command
  • "git checkout master" then "git checkout –b feature/a"
  • To make a new file in it "echo "# regex-git-internship-filea" >> a.md" then "git status" then "git add ." then "git commit –m “first commit in branch a” then "git push" then "git push –set-upstream origin feature/a"

We can see that new branch has been made but "a.md" cannot be seen in master branch so what will do is "COMPARE AND PULL REQUEST" then "OPEN A PULL REQUEST" (that whatever code written in "a.md" will tell to compare and see if code is right.

No alt text provided for this image

Push

This command syncs commits between your local and remote repositories. Pull operation is the polar opposite of push operation. Pushing commits to distant repositories, whereas pulling imports commits to local repositories.

Git push is a command that pushes your local modifications to a central repository. When one has accumulated multiple local commits and is ready to share it with the rest of the team, use the following command to push them to the central repository:

$ git push <remote>        

Note: When using the pull command, this remote refers to the remote repository that was previously configured.

This syncs the changes from the local repository to the remote repository, including all commits and internal objects. In the target repository, this generates a local branch.

$ git push origin master        

This command is used to reflect the already committed files in the master branch of the central repository.

Git does not enable push when it results in a non-fast forward merging in the destination repository to prevent overwriting.

$ git push <remote> --force        

Even if the push operation results in a non-fast forward merging, the above instruction forces it.?

  • Command 1:?echo "# regex-git-internship" >> README.md
  • Command 2:?git init (Initialized empty Git repository in C:/Users/HP/Downloads/Regex Git Internship/.git/)
  • Command 3:?git remote add origin https://github.com/dhruvbhatia563/regex-git-internship.git
  • Command 4:?git add README.md
  • Command 5:?git commit -m "my first commit"
  • Command 6:?git push
  • Command 7:?git push --set-upstream origin master

Creating a new repository.

A repository (usually abbreviated to “repo”) is a location where all the files for a particular project are stored. Each project has?its own repo, and you can access it with a unique URL.

No alt text provided for this image


  • Need to create a new repository and click on the plus sign.
  • Fill up all the required details, i.e., repository name, description and also make the repository public this time as it is free.
  • merge "a.md" in master branch and make it one) then "create a pull request" then "merge pull request" then "confirm merge".
  • Now can see that "a.md" is present in?MASTER?branch
  • To?DELETE?the branch from?server?-- go to pull request and delete the branch from server
  • To?DELETE?branch from?local machine?use command "git branch" then "git checkout master" then "git branch –D feature/a"

"git pull" to come back to origin/master - basically to update local branch.

Git Clone

What is the use of git clone and how to use it?

The?git clone?command is used to duplicate a repository or a branch inside a repository.

Git is a version control system that is distributed. By cloning, you may reap the benefits of having a whole repository on your own workstation.

git clone https://github.com/github/training-kit.git        

When?one?clones?a?repository,?unlike?other?centralised?version?control?systems,?one?does not?obtain?a?single?file.?When?one?clones?a?repository?with?Git,?his/she?gets?the?complete?repository,?including?all?files,?branches,?and?commits.

Cloning?a?repository?is?usually?done?only?once,?at?the?start?of?a?project's?interaction?with?him. One would clone a repository that already exists on a remote, such as GitHub, so that one could interact with it locally. One would not need to clone a repository again to undertake normal development once he/she has cloned it.

All developers will be able to work more freely now that they have access to the complete repository. Working on a feature branch allows one to make changes without being constrained by the files one can work on.

No alt text provided for this image

  • Using?git push, one may share his/her branch with the remote repository.
  • Create a pull request with ones colleagues to compare the changes.
  • Test and deploy as needed from the branch.
  • merge into the?master?branch.

?Most?common?uses?and?options of?git?clone:

No alt text provided for this image


$ git clone [url]        

  • Clone?(download)?an?existing?GitHub?repository,?including?all?of?its?files,?branches,?and?commits.

$ git clone --mirror        

  • Clone?a?repository?but?don't?have?access?to?any?of?the?files.?This?comprises?the?references,?often?known?as?branches. If?one is?trying?to?create?a?secondary?copy?of?a?repository?on?a different?remote?and?want?to?match?all?of?the?branches,?this?is?the?method?to?utilise.?This?can happen?when?setting?up?a?new?remote?for?your?Git?hosting?or?while?running?automated?tests?with?Git.

$ git clone --single-branch        

  • Clone only a single branch

$ git clone --sparse        

  • Instead?of?recursively?populating?the?working?directory?with?all?of?the?files?in?the?current?commit,?only?populate?the?root?directory?with?files.?When?cloning?big?repositories?with?many?directories?and?sub-directories,?this?could?aid?with?performance.

$ git clone --recurse-submodules[=<pathspec]        

  • Initialize and clone submodules within the clone depending on the specified pathspec after it has been built. This is a nice choice if one is cloning a repository with submodules that one will be using as dependents in his/her local development.
  • If want to access repository directly from Git Bash have to copy the repository GitHub URL from the browser and use the following command
  • git clone https://github.com/dhruvbhatia563/regex-git-internship

Result?:

  • Cloning into 'regex-git-internship'...
  • remote: Enumerating objects: 11, done.
  • remote: Counting objects: 100% (11/11), done.
  • remote: Compressing objects: 100% (6/6), done.
  • remote: Total 11 (delta 1), reused 9 (delta 0), pack-reused 0
  • Receiving objects: 100% (11/11), done.
  • Resolving deltas: 100% (1/1), done.

Use Command: "cd regex-git-internship/" then use command "git status"

Branch

What do you mean by Branch?

No alt text provided for this image

Working on multiple versions of a repository at the same time is known as branching.

Few common branch names used are:

  • Master:?The code which is live/finalized.
  • Develop:?Not yet live/finalized, but working code. Many Developers work on it actively.
  • Feature:?To work in an isolated environment while making new changes.
  • Release:?Branch used only to push code to live servers.

A repository contains one main branch by default, which is considered the definitive branch. Branches are used to test and make changes before committing them to the main branch.

When one builds a branch off the main branch, he/she is essentially producing a replica of main as it was at the moment. One could pull in updates from the main branch if they were made while one was working on his/her branch.

Let's imagine you want to add a new feature (which is still in development), but you're unsure whether or not to make changes to your primary project. Branches allows one to switch back and forth between different project states/versions. In the example, one may establish a new branch and test the new feature without affecting the master branch. When finished, merge the changes from the new branch into the main branch. The master branch is the main branch in this case, which is present by default in your repository.

● Which branch should be used to keep deployment-ready code?

There is a?master/production branch?with a fresh branch for testing that is used to keep the deployment-ready code, as shown in the above figure. Two sets of changes are made under this branch, and once they are finished, they are merged back into the main branch.

● Create a new branch called development from the main branch.

We can use the?git branch?command to create, list branches on the command line.

$?git branch <branch name>

$ git branch developement        

To create a new branch using the Git command line and to switch to the newly created branch, issue the command:

$?git checkout?<branch name>

$ git checkout developement        

○?Checkout one more branch deployment from the previous branch.

$ git checkout -b deployement developement        

○ Push different data into both branches.

$ git push origin developement
$ git push origin deployement        

○ Merge data from both branches to the main branch.

$ git checkout developement
$ git merge main        

A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit process. The?git branch?command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. For this reason,?git branch?is tightly integrated with the?git checkout?and?git merge?commands.

git?branch
?        

List all of the branches in your repository. This is synonymous with?git branch --list.

git?branch?<branch>
?        

Create a new branch called?<branch>. This does?not?check out the new branch.

git?branch?-D?<branch>
?        

Force delete the specified branch, even if it has unmerged changes. This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development.

Branch A, Branch B and Branch C corresponds to Git Local Branches on a developer workstation. Mainline branch strategy is the simplest yet most effective strategy for small to medium sized teams.?The developers in the team constantly commit their work into a single, central branch—which is always in a deployment-ready state. In other words, the main branch for the project should only contain tested and quality work, and should never be broken.

Create a new branch called "development" from the main branch. checkout one more branch "deployment" from the previous branch. Push different data in both the branches. Merge data from both the branches to the main branch.

  • Command 1: git checkout -b development
  • Command 2: git push
  • Command 3: git push --set-upstream origin development

Now in Branch - Development will create another branch called "deployment" and will?push?a file in deployment branch and with pull request will merge contents of the both the branches -- "Development" & "Deployment"?

  • Command 1: git checkout -b deployment
  • Command 2: echo "# regex-git-internship-x" >> x.md
  • Command 3: git status
  • Command 4: git add .
  • Command 5: git status
  • Command 6: git commit -m "commit"
  • Command 7: git push
  • Command 8: git push --set-upstream origin deployment

Now will create a?Pull request?to merge the content of both the branches "Development" & "Deployment". After merging will?delete the branch deployment?both from local and server. So at the end will be left with only 2 branches -- "Master Branch" [having all latest codes] and "Development Branch" [having codes ready to be released in a version]?

Click on -- "create pull request"

Click on "merge pull request"

Click on?"confirm merge"

As from the above image - we can see that the "deployment" branch has been successfully merged with the "development" branch will not click on -- "Delete Branch" as it will delete the branch "deployment" from the Git Repository.

Now to "DELETE" the branch "deployment" from the local machine, will use the following command line:

  • Command 1: git checkout master
  • Command 2: git branch
  • Command 3: git branch -D deployment

Will now make a?pull request?to merge the content of the branch "Development" with the "Master" branch

Click on "merge pull request"

Click on?"confirm merge"

As the branch "deployment" has now been deleted from both?local and server?will make changes in local machine already been done on server for the will use following command lines:

  • Command 1: git fetch
  • Command 2: git status
  • Command 3: git pull

Steps To Ignore Files in Git | .gitignore file

.gitignore?file -- can be used to ignore specific file extensions from being included in git working copy.

For example -- While working on a specific folder, we created a test file by name -- "test.py" but have no intention to push it to the server. In that case .gitignore?file will come into picture.

As we write command "git status" Git Bash will show us one?Untracked file?which is?"test.py"

Now, In order to?ignore?this "test.py" file and avoiding it to?push it to the server?will now use .gitignore?command as follows:

Command: touch .gitignore -- this will create .gitignore folder?in the specified folder which we are working on.

Now will add?"test.py" file in .gitignore folder.

From the above image we can see that "test.py" file has been ignored and now it has been added in .gitignore folder.

IMPORTANT POINT TO REMEBER --?HAVE TO USE "git add .gitignore" in order to always track this folder if in future again if struck will some file/folder we wish to ignore.

After refreshing the GitHub Repository we can clearly see that test.py file has not been pushed and it has been clearly ignore with .gitignore folder


Ranjeet Kumar

Sr. Project Manager-DATA | AWS Certified Solution Architect | SAFe POPM | CSM | PRINCE2 | ITIL

3 年

Good article !!

要查看或添加评论,请登录

Rajni Shiv Kant的更多文章

  • What is Amazon AWS IAM?

    What is Amazon AWS IAM?

    AWS Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources. You…

  • What is Docker..?

    What is Docker..?

    Docker is an open platform for developing, shipping, and running an applications. Docker enables you to separate your…

    3 条评论
  • Master Class on Linux

    Master Class on Linux

    What is Linux? Just like Windows, IOS, and Mac OS, Linux is an operating system. In fact, one of the most popular…

社区洞察

其他会员也浏览了