Essential Git Command Reference: The Core Operations Every Developer Needs
2 May 20254 min read
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.
This 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.
Example:
This 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.
You’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 #file
adds 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.
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.
This helps you preview what’s going to be committed or what changed between commits.
7. git log
Displays the commit history.
You’ll see:
- Commit hashes
- Author names
- Dates
- Commit messages
To simplify the view:
This 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:
Undo a commit (but keep your changes):
Undo a commit and remove changes:
⚠️ Be careful with --hard
— it deletes your changes.
9. git checkout
Switches branches or restores files.
Switch to a branch:
Restore a file to the last committed version:
Since Git 2.23, the safer alternative is to use:
10. git branch
Lists, creates, or deletes branches.
List branches:
Create a new branch:
Delete a branch:
11. git merge
Combines changes from one branch into another.
This 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.
This is equivalent to:
Use git pull --rebase
to avoid unnecessary merge commits.
13. git push
Uploads your local commits to a remote repository.
Use this to share your work with others.
14. git stash
Temporarily saves changes that you don’t want to commit yet.
This clears your working directory so you can switch branches cleanly.
Restore stashed changes:
View all stashes:
15. git remote
Manages remote repositories.
List remotes:
Add a new remote:
Rename a remote:
Final Tips
- Use
git status
andgit log
often — 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.