DEV Community

Cover image for Git at a Glance: A Cheatsheet of 30 Must-know Commands
Muhammad ABir
Muhammad ABir

Posted on

Git at a Glance: A Cheatsheet of 30 Must-know Commands

Managing code and collaborating with others can be a daunting task, but Git makes it easy. This cheatsheet is here to help you take your Git skills to the next level by providing a comprehensive list of 30 essential commands. From initializing a new repository to merging changes, this cheatsheet covers all the basics you need to know to streamline your workflow and make your life as a developer much easier. Whether you're new to Git or an experienced user, this cheatsheet is a valuable resource to have on hand.

  1. Initialize a new repository: git init
  2. Clone an existing repository: git clone [repository url]
  3. Check the status of your repository: git status
  4. Add changes to the staging area: git add [file name]
  5. Commit changes: git commit -m "[commit message]"
  6. View the commit history: git log
  7. View the difference between the working directory and the staging area: git diff
  8. View the difference between the staging area and the last commit: git diff --staged
  9. Discard changes in the working directory: git checkout [file name]
  10. Discard changes in the staging area: git reset [file name]
  11. Discard a commit: git revert [commit hash]
  12. Remove a file from the repository: git rm [file name]
  13. Rename a file in the repository: git mv [old file name] [new file name]
  14. Show the branches in the repository: git branch
  15. Create a new branch: git branch [branch name]
  16. Switch to a different branch: git checkout [branch name]
  17. Merge changes from one branch to another: git merge [branch name]
  18. Show remote repositories: git remote
  19. Show remote repositories: git remote -v
  20. Add a new remote repository: git remote add [remote name] [repository url]
  21. Push changes to a remote repository: git push [remote name] [branch name]
  22. Pull changes from a remote repository: git pull [remote name] [branch name]
  23. Show the tags in the repository: git tag
  24. Create a new tag: git tag -a [tag name] -m "[tag message]"
  25. Checkout a specific tag: git checkout [tag name]
  26. Show the history of a file: git log -p [file name]
  27. Show the commits that contain a certain string: git log -S [string]
  28. Show the commits that were made by a certain author: git log --author=[author name]
  29. Show the commits that were made in a certain date range: git log --since=[date] --until=[date]
  30. Show the commits that were made on a certain branch: git log [branch name]

Please note that this is a list of commonly used Git commands, and there are many other commands that you can use as well. Additionally, each command has many options and flags that can be used to customize its behavior. I would suggest you to use the official Git documentation to learn more about the various commands and their usage.

Oldest comments (0)