Software development is all about writing code and developing solutions following requirements and processes. Managing code becomes complex with time and multiple contributors. In the real scenario, multiple developers work on the same project and write code on a daily basis. Tracking changes and merging those codes are hassle and time consuming without any proper tools or platforms. Another issue along with is roll back which is not possible without using any version control tools. When it comes to writing code, source code management is another important factor to consider. Source code management is not only just storing the code safely but also tracking the changes, resolving the conflicts, and merging from multiple contributors.

To more about Git, and GitHub, please check this article. Click Here

In this article, I will share some most useful git commands for all developers and programmers which are used in daily basis working with git repositories.

Git is a version control system for managing the source code which keeps the track of it with many options. Basically, it is a software to track the changes of files mostly used for coders to work collaboratively and source code management during the software development.

As per Git-SCM (https://git-scm.com/)

Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git Commands

Below are the top most git commands for programmers and developers.

Git Init

Git Clone

Git Add

Git Config

Git Add

Git Remove

Git Commit

Git Pull

Git Push

Git Reset

Git Status

Git Branch

Git Diff

Git Checkout

Git Merge

Git Stash

Git Log

Git Init

To initialize a new git repository. Namely, to start git repository

git init
git init [repository name]

simply navigate to folder which you want to add in git repository and run this command.

Git Clone

This command is to create a local copy of a remote git repository through URL.

git clone [URL]
Git Status

To check the status of git.

git status

Git Config

To configure git author with name and email.

git config -global user.name “[user_name]”
git config -global user.email “[user_email]”
git config -local user.name “[user_name]”
git config -local user.email “[user_email]”

Git Add

This command is used for adding file(s) to git repository.

git add [file_name]

To add all modified files

git add -A 
git add .
git add *

Note: this will add the file(s) into staging area.

Git Remove

To remove the file or folder from your working directory and stages deletion.

git rm [file_name]
git rm -r [file_name]

Git Commit

To commit changes into git version history.

git commit -m “commit message”
git commit -a

Above commit command will commits all the files you have added via git or modified.

Git Pull

To fetch and merge the latest commit from remote server to your local working directory.

git pull
git pull [branch_name]
git pull orgin [branch_name]

Git Push

To push the changes to remote repository.

git push
git push -u origin [branch_name]

Push the changes to the branch.

git push -all

Git Reset

To reset the uncommitted file

git reset [file_name]

To undo all commits after certain commit and preserve the changes in working directory.

git reset [commit]

To go back to specified commit.

git reset --soft [commit]
git reset --hard [commit]

Git Status

This status of files and list of pending commits.

git status

Git Branch

This command gives list of branches.

git branch

To list all branches including local and remote.

git branch -a

To create a new branch.

git branch [branch_name]

To delete a branch.

git branch -d [branch_name]

To delete remote branch.

git push origin --delete [branch_name]

To rename a local git branch.

git branch -m [old_branch_name]  [new_branch_name]

 Git Diff

To show the differences of file which are not committed yet.

git diff -staged

Above command will show the differences in files in the staging area with latest remote git repository.

To preview the changes between two branches before merging.

git diff [one_branch_name] [another_branch_name]

Git Checkout

To switch the branch

git checkout [branch_name]

To switch to last checked out

git checkout – [file_name]

Git Merge

To merge specific branch into current branch

git merge [branch_name]

To merge one branch into another branch

git merge [source_branch] [target_branch]

Git Stash

It changes in a dirty working directory

git stash

Remove all stashed entries

git stash clear

Git Log

To view the version or change history.

git log

To view summary in detail

git log --summary

 To view log in brief

git log --oneline

Conclusion

In this article, I have shared most used git commands specially for developers. There are several other commands available for git, however, above mentioned are top most and popular commands.

By Rijwan Ansari

Research and Technology Lead | Software Architect | Full Stack .NET Expert | Tech Blogger | Community Speaker | Trainer | YouTuber. Follow me @ https://rijsat.com Md Rijwan Ansari is a high performing and technology consultant with 10 plus years of Software Development and Business Applications implementation using .NET Technologies, SharePoint, Power Platform, Data, AI, Azure and cognitive services. He is also a Microsoft Certified Trainer, C# Corner MVP, Microsoft Certified Data Analyst Associate, Microsoft Certified Azure Data Scientist Associate, CSM, CSPO, MCTS, MCP, with 15+ Microsoft Certifications. He is a research and technology lead in Tech One Global as well as leading Facebook community Cloud Experts Group and SharePoint User Group Nepal. He is a active contributor and speaker in c-sharpcorner.com community, C# Corner MVP and his rank at 20 among 3+ millions members. Additionally, he is knee to learn new technologies, write articles, love to contribute to the open-source community. Visit his blog RIJSAT.COM for extensive articles, courses, news, videos and issues resolution specially for developer and data engineer.

Leave a Reply

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