Most frequently Used Git Commands For Developers

Posted by

Git is a version control system that tracks the changes in your project. Git is an essential aspect of day-to-day programming (particularly if you work in a team) and is extensively utilized in the software development industry.

As there are so many different commands to know, learning Git takes time. However, certain Git commands are used more frequently. So, in this post, explain the most frequently used Git Commands that every developer should be familiar with.

Initialize Repository

It will initialize the project folder into a git repository.

Checking Git version

It displays the version of Git that is currently installed on your PC.

Git Status Checking

It will show you exactly which files/folders have been modified.

The below git command shows the short status.

Staging Files

git add

Add file changes to the git staging area.

You can add all changes by using the below command.

To add a single file to the staging area using the below git command.

To add multiple files to the staging area using the below git command.

Stages the files using a pattern.

The below command controls the source code commit. It provides the yes/no options for adding the code to the git staging area.

git diff

It will differentiate between a file in the staging area and a file in the working tree ( Untracked file ).

Commit the staged/added files

It will save your changes to your local repository. It’s good practice to include a proper commit message which helps in debugging.

You can bypass the staging area using the below command.

git push

It will push all the local changes that you’ve made to the remote Github repository.

git pull

It will pull ( fetch ) all updated code from the remote branch and merge it with your local branch.

git log

It will display your whole commit history, which includes all of the commits you’ve made till now.

git branch BranchName

This command adds a new branch to your local git repository.

git branch

It will display a list of all the local branches you’ve created.

git branch -a

It will display all of the branches, both local and remote, that are available for checkout.

git branch -D BranchName

It will remove the selected local branch forcibly ( even if the changes are not committed ).

git checkout

It refers to switching between local git branches.

git stash

It allows you to save the changes locally and it allows you to do other git operations.

git remote

It will give the name of the remote repository.

For e.g, ” origin ” or ” upstream ”

git reset

if do you want to undo the commit, you can use the below git command.

git revert CommitId

If you want to revert the particular commit then you can use the below command.

You can get the CommitID using the git log command.

git remote -v

It will give the name as well as the URL of the remote repository.

Remove folder from git:

We use the below command to remove the folder from the git.

Commit the change and push the change to your remote repository.

 

These are the Most frequently Used Git Commands. You can read About Git from the Github site.

Leave a Reply

Your email address will not be published. Required fields are marked *