Git Terminologies and commands

Git Terminologies and commands

Hellooo Everyone! Are you a beginner in Git? If yes, this guide contains the high level flow of git and the commands that are widely used.

What is Git?

Git is most widely used version control system. It keeps track of every change made to the code. If a mistake is made, developers can restore previous versions of code and then fix the mistake made. Also, if many people are working on the same project, by using git, it becomes easier to see the updated changes. The branching, which is the process of making copy of the main branch, and then the developer can workon his/her branch individually, and then merge it, this process helps in developing multiple features at same time.

Understanding terms in git

Git has a vast pool of new terms that may be quite overwhelming in the beginning. But as you start using them, git becomes easier to understand and then you will realise the magic of git.

Repository

Repository in Git is considered as the project folder.

Branch

A branch is a version of the repository that diverges from the main working project. A Git project can have more than one branch.

Checkout

In Git, the term checkout is used for the act of switching between different versions of a target entity. The git checkout command is used to switch between branches in a repository.

Fetch

It is used to fetch branches and tags from one or more other repositories, along with the objects necessary to complete their histories. It updates the remote-tracking branches.

HEAD is the representation of the last commit in the current checkout branch. We can think of the head like a current branch. When you switch branches with git checkout, the HEAD revision changes, and points the new branch.

Fork

A fork is a rough copy of a repository. Forking a repository allows you to freely test and debug with changes without affecting the original project.

Merge

Merging is a process to put a forked history back together. The git merge command facilitates you to take the data created by git branch and integrate them into a single branch.

Push

The push term refers to upload local repository content to a remote repository. Pushing is an act of transfer commits from your local repository to a remote repository. Pushing is capable of overwriting changes; caution should be taken when pushing.

Pull

The term Pull is used to receive data from GitHub. It fetches and merges changes on the remote server to your working directory.

Pull requests are a process for a developer to notify team members that they have completed a feature. Once their feature branch is ready, the developer files a pull request via their remote server account. Pull request announces all the team members that they need to review the code and merge it into the master branch. In simpler words, a "pull request" is you requesting the target repository to please grab your changes.

Clone

It is used to make a copy of the target repository or clone it. If I want a local copy of my repository from GitHub, this tool allows creating a local copy of that repository on your local directory from the repository URL.

Widely used Git Commands

git init

It is used to create a local repository. 1git.jpg

git status

The status command is used to display the state of the working directory and the staging area. It allows you to see which changes have been staged, which haven't, and which files aren't being tracked by Git. 2git.jpg

git clone

It is used to make a copy of a repository from an existing URL. If you want a local copy of a repository from GitHub, this command helps in creating local copy of repository using the URL. 3git.jpg

git add

It is used to add one or more files to staging (Index) area. 4git.jpg Here,

I created new file 'try4.txt'. Then, I checked the status of the repository. It says there is new file added. Then I used git add command to add the file to staging area.

git commit It commits the files added in the repository with git add. 5git.jpg

git push

It is used to push, in other words, upload the code from local to remote repository. Pushing is capable of overwriting changes, and caution should be taken when pushing. 6git.jpg

git pull

It is used to receive data from GitHub. It fetches the changes and merges from remote repository to the local repository. 7git.jpg