30 Useful Git Commands Every Developer Should Know

Git is an open-source distributed version control system. In a nutshell, it is used to track changes in any set of files, usually for managing work among developers (programmers) collaboratively developing source code during software development. This helps in speed, data integrity, and support for distributed, non-linear workflows.

Here are some git commands that can help you to accelerate your understanding and usage of git as a developer:

 1. git init

 Initializes a new Git repository

2. git init [project name]

  Alternatively, you can create a repository within a new directory by specifying the project name

3. git add <files>

Adds files to the staging area. You can use 'git add .' to add all modified files.

4. git reset

Undoes the changes to the local files, and restores to the last commit.

5. git diff

Displays the difference between files in two commits or between a commit and your current repository.

6. git status

It is used to check the state of the staging area and the working directory.

7. git commit -m "message"

This command is used to commit files (locally) to the repository.

8. git log

It is used to view the entire commit history.

9. git clone

Used to download existing code from a remote repository.

10. git branch

Used to list all the local branches on the machine.

11. git branch <branch-name>

Used to create a new branch locally.

12. git branch -d <branch-name>

Used to delete a branch.

13. git branch -m <new-name>

Used to rename the current working branch.

14. git merge <branch-name>

Merges the provided branch with the current working branch.

15. git checkout <branch-name>

Used to switch from current branch to another one.

16. git checkout -b <branch-name>

Creates a new branch and switches to the new one.

17. git push <remote> <branch-name>

Used to save all commits to the remote repository.

18. git pull <remote>

Used to pull down all the updates from the remote repository.

19. git rm <file-name>

Used to remove a file from the working directory.

20. git stash

It is used to remove uncommitted changes temporarily.

21. git stash list

List all the uncommitted changes that were removed temporarily 

22. git stash drop

Discards the changes from the top of the stash stack

23. git remote –v

Git remote lets you view all remote repositories. The following command will list all connections along with their URLs.

24. git merge <branch-name>

Used to merge a branch into the active one

25. git diff --base <file-name>

Lists down conflicts. In order to view conflicts against the base file, use

26. git rebase master

This is used to apply certain changes from one branch to another.

27. git show [SHA]

Shows any object in Git in human-readable format

28.  git gc

Cleans unnecessary files and optimizes the local repository

29. git fsck

performs an integrity check of the git file system and identifies any corrupted objects

30. git tag <insert-commitID-here>

Marks specific commits.  Developers usually use it to mark release points like v1.0 and v2.0.


Learning git commands will help you as a developer to easily control project source code. The learning curve might be steep but hopefully, this GIT cheat sheet will be helpful for you. 

Practice those commands and make the most of your developing skills! 

Be the first to comment

Leave a Reply

Your email address will not be published.