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