Git is one of those tools you'll use almost every day, whether you're building applications, collaborating with a team, or managing deployment pipelines. While there are hundreds of Git commands available, only a handful become part of your daily workflow.
This guide covers 30 practical Git commands that every developer, DevOps engineer, and software engineer should know. Instead of memorizing them, focus on understanding when to use each one.
1. Initialize a Repository
git init
Creates a new Git repository in your current project folder so version control can begin.
2. Clone an Existing Repository
git clone <repository-url>
Downloads an existing Git repository from GitHub or another Git provider to your local machine.
3. Check Repository Status
git status
Shows modified, staged, and untracked files so you always know the current state of your project.
4. Stage Specific Files
git add <filename>
Adds selected files to the staging area before creating a commit.
To stage everything:
git add .
5. Commit Your Changes
git commit -m "Describe your changes"
Saves the staged changes as a new snapshot in the repository with a meaningful commit message.
6. Upload Changes
git push
Pushes your local commits to the remote repository.
7. Download Latest Changes
git pull
Fetches updates from the remote repository and merges them into your current branch.
8. View Commit History
git log
Displays the project's commit history along with author information and timestamps.
9. List All Branches
git branch
Shows every local branch available in your repository.
10. Create a New Branch
git checkout -b feature/login
Creates a new branch and immediately switches to it.
11. Switch Between Branches
git checkout main
Moves your working directory to another branch.
12. Merge Another Branch
git merge feature/login
Combines changes from another branch into your current branch.
13. View Remote Repositories
git remote -v
Displays the configured remote repositories and their URLs.
14. Add a Remote Repository
git remote add origin <repository-url>
Connects your local repository to a remote Git server.
15. Remove a Remote
git remote remove origin
Deletes a configured remote repository.
16. Compare Changes
git diff
Shows the differences between your working directory, staged files, and commits.
17. Fetch Without Merging
git fetch
Downloads the latest commits from the remote repository without changing your current branch.
18. Save Work Temporarily
git stash
Temporarily stores uncommitted changes so you can switch tasks without committing unfinished work.
Restore them later:
git stash pop
19. Unstage a File
git reset <filename>
Removes a file from the staging area while keeping your local modifications.
20. Delete a Tracked File
git rm <filename>
Deletes a file and stages that deletion for the next commit.
21. Configure Git Identity
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Sets the default identity used for all your commits.
22. Create a Version Tag
git tag v1.0.0
Creates a tag that marks an important release or milestone.
Push tags using:
git push --tags
23. Delete a Branch
git branch -d feature/login
Removes a branch that has already been merged.
24. Rebase a Branch
git rebase main
Moves your branch on top of another branch to maintain a cleaner project history.
25. Abort a Merge Conflict
git merge --abort
Cancels an ongoing merge and restores the repository to its previous state.
26. Apply a Single Commit
git cherry-pick <commit-hash>
Copies a specific commit from another branch without merging the entire branch.
27. Remove Stale Remote Branches
git fetch --prune
Deletes local references to remote branches that no longer exist.
28. Clean Untracked Files
git clean -df
Removes untracked files and folders from your working directory.
Use this carefully because deleted files cannot be recovered through Git.
29. Initialize Git Submodules
git submodule update --init --recursive
Downloads and initializes all project submodules.
This is commonly required after cloning repositories that depend on external projects.
30. Clone with Submodules
git clone --recurse-submodules <repository-url>
Clones the repository and automatically downloads all associated submodules in one step.
Final Thoughts
Learning Git isn't about memorizing every available command. It's about becoming comfortable with the commands you'll use repeatedly throughout development.
If you can confidently work with branching, committing, merging, fetching, rebasing, and resolving conflicts, you'll be prepared for most real world Git workflows.
Which Git command do you use the most? Share it in the comments, and if you think I missed one that deserves a place in this list, I'd love to hear your suggestions.
Happy coding! π
Top comments (0)