Top 20 Most Used Git Commands For Developers

Adina Socaci
2 min readJun 10, 2023

--

For developers, being familiar with the top 20 Git commands can prove to be incredibly useful. These commands are complete with explanations and examples, making it easier for you to master them and enhance your development skills.

  1. git init: Initializes a new Git repository in the current directory. Example: git init
  2. git clone: Copies a remote repository to your local machine. Example: git clone https://github.com/example/repo.git
  3. git add: Stages changes for commit. Example: git add file.txt
  4. git commit: Records staged changes to the repository. Example: git commit -m "Added new feature"
  5. git push: Uploads local commits to a remote repository. Example: git push origin main
  6. git pull: Retrieves and merges changes from a remote repository. Example: git pull origin main
  7. git status: Displays the current state of the repository. Example: git status
  8. git branch: Lists, creates, or deletes branches. Example: git branch, git branch new-branch, git branch -d branch-to-delete
  9. git checkout: Switches between branches or restores files from a specific commit. Example: git checkout branch-name, git checkout commit-hash file.txt
  10. git merge: Combines changes from different branches. Example: git merge branch-name
  11. git remote: Manages remote repositories. Example: git remote add origin https://github.com/example/repo.git
  12. git log: Displays the commit history. Example: git log
  13. git diff: Shows differences between commits, branches, or files. Example: git diff, git diff branch1 branch2, git diff file.txt
  14. git stash: Temporarily saves changes that are not ready to be committed. Example: git stash, git stash apply
  15. git reset: Undoes changes, unstages files, or moves the HEAD pointer. Example: git reset HEAD file.txt, git reset --hard commit-hash
  16. git rebase: Integrates changes from one branch onto another. Example: git rebase branch-name
  17. git tag: Marks a specific commit with a version or label. Example: git tag v1.0.0
  18. git fetch: Retrieves changes from a remote repository without merging. Example: git fetch origin
  19. git cherry-pick: Applies a specific commit to the current branch. Example: git cherry-pick commit-hash
  20. git config: Configures Git settings. Example: git config --global user.name "John Doe"

--

--

Adina Socaci
Adina Socaci

Written by Adina Socaci

Tech | Science | Languages | Having Fun

No responses yet