If you’re new to Git or only use it occasionally, you’ve likely googled “most useful Git commands” more than once. This guide is for you. It won’t cover everything Git can do, but it focuses on the most practical commands that will save you time and headaches during day-to-day development.
Let’s dive in.
1. git init
Creates a new Git repository in the current folder.
git initThis sets up Git tracking for your project. It creates a .git directory containing metadata about your repo, including commit history, branches, and remote settings.
2. git clone
Creates a local copy of a remote repository.
git clone #repository-urlExample:
git clone https://github.com/test/hello-world.gitThis copies all the files, history, and branches from the remote repo.
3. git status
Shows the current state of your working directory and staging area.
git statusYou’ll see:
- Files that have been modified
- Files that are staged
- Untracked files
This is one of the most frequently used Git commands.
4. git add
Adds files to the staging area so they’re ready to be committed.
git add #filegit add .-
git add #fileadds a specific file. -
git add .adds all changes in the current directory and subdirectories.
Tip: Use git status before running this to see which files you’re staging.
5. git commit
Saves a snapshot of your staged changes with a message.
git commit -m "@feature auth added"Each commit should describe why the changes were made—not just what was changed.
Use clear, concise messages that help teammates (and your future self) understand the history.
6. git diff
Shows differences between your working directory and the staging area or between commits.
git diff # changes not yet stagedgit diff --staged # staged but not yet committedThis helps you preview what’s going to be committed or what changed between commits.
7. git log
Displays the commit history.
git logYou’ll see:
- Commit hashes
- Author names
- Dates
- Commit messages
To simplify the view:
git log --oneline --graph --decorateThis gives a compact visual history with branches and tags.
8. git reset
Resets your staging area or moves HEAD to a different commit.
Undo staged changes:
git reset #fileUndo a commit (but keep your changes):
git reset --soft HEAD~1Undo a commit and remove changes:
git reset --hard HEAD~1⚠️ Be careful with --hard — it deletes your changes.
9. git checkout
Switches branches or restores files.
Switch to a branch:
git checkout mainRestore a file to the last committed version:
git checkout -- index.htmlSince Git 2.23, the safer alternative is to use:
git restore #filegit switch #branch10. git branch
Lists, creates, or deletes branches.
List branches:
git branchCreate a new branch:
git branch @feature/login-formDelete a branch:
git branch -d old-feature11. git merge
Combines changes from one branch into another.
git checkout maingit merge @feature/login-formThis merges the feature branch into the main branch.
If there are conflicting changes in the same files, Git will prompt you to resolve them manually.
12. git pull
Downloads changes from a remote repository and merges them into your local branch.
git pull origin mainThis is equivalent to:
git fetchgit mergeUse git pull --rebase to avoid unnecessary merge commits.
13. git push
Uploads your local commits to a remote repository.
git push origin mainUse this to share your work with others.
14. git stash
Temporarily saves changes that you don’t want to commit yet.
git stashThis clears your working directory so you can switch branches cleanly.
Restore stashed changes:
git stash popView all stashes:
git stash list15. git remote
Manages remote repositories.
List remotes:
git remote -vAdd a new remote:
git remote add origin https://github.com/user/repo.gitRename a remote:
git remote rename origin upstreamFinal Tips
- Use
git statusandgit logoften — they’re your safety net. - Don’t be afraid of branching and stashing — they help you experiment safely.
- Always write meaningful commit messages.
Learning these 15 commands gives you a strong foundation for working with Git in most real-world scenarios.