Git is a free, open-source distributed version control system created by Linus Torvalds.
It helps developers:
Learn how to write computer programs
- Track changes in their code over time
- Revert to previous versions
- Collaborate with teammates without overwriting each other’s work
- Experiment safely using branches
- Maintain a history of updates, features, and fixes
With Git, every developer has a full copy of the repository on their machine, making it fast, reliable, and able to work offline.
Learn how to use Git version control
What Git Is Used For
Git is commonly used to:
✅ 1. Save and manage project versions
Every commit records a snapshot of your project.
✅ 2. Work in branches without conflicts
Develop features independently and merge them later.
✅ 3. Collaborate on the same codebase
Multiple developers can work simultaneously without collisions.
✅ 4. Backup code on remote services
Platforms like GitHub, GitLab, Bitbucket store your code online.
✅ 5. Review and audit changes
Git logs, diffs, and blame help you track who changed what — and why.
Comprehensive List of Git Commands and Their Usage
1. Configuration Commands
| Command | Usage |
|---|
git config --global user.name "Name" | Set your Git username |
git config --global user.email "[email protected]" | Set your Git email |
git config --list | Display all Git configurations |
git config --global core.editor "editor" | Set default text editor |
git config --global color.ui auto | Enable colored output |
2. Getting Help
| Command | Usage |
|---|
git help <command> | Help for a command |
git <command> --help | Detailed manual |
git help -a | List all Git commands |
3. Repository Setup
| Command | Usage |
|---|
git init | Initialize a new local repository |
git clone <url> | Clone an existing repository |
4. Basic Snapshotting (Staging & Committing)
| Command | Usage |
|---|
git add <file> | Stage a file |
git add . | Stage all changes |
git status | Show current status of the repo |
git commit -m "message" | Commit staged changes |
git commit -am "message" | Add & commit tracked files |
git rm <file> | Remove a file and stage the deletion |
git mv <old> <new> | Rename a file |
5. Branching & Merging
| Command | Usage |
|---|
git branch | List branches |
git branch <name> | Create a new branch |
git branch -d <name> | Delete a branch |
git checkout <branch> | Switch to a branch |
git checkout -b <branch> | Create and switch to a branch |
git switch <branch> | Modern way to switch branches |
git switch -c <branch> | Modern way to create + switch |
git merge <branch> | Merge a branch into current one |
git rebase <branch> | Reapply commits on top of another branch |
6. Remote Repositories
| Command | Usage |
|---|
git remote | List remotes |
git remote -v | List remote URLs |
git remote add origin <url> | Connect local repo to remote |
git remote remove <name> | Remove a remote |
git fetch | Download changes without merging |
git pull | Fetch + merge changes |
git pull --rebase | Fetch + rebase |
git push | Upload commits to remote |
git push -u origin <branch> | Push branch and set upstream |
🔵 7. Inspecting Changes
| Command | Usage |
|---|
git log | Show commit history |
git log --oneline | Short commit history |
git log --graph --oneline | Visual commit tree |
git diff | Show unstaged changes |
git diff --staged | Show staged changes |
git show <commit> | Show specific commit details |
8. Undoing Changes
| Command | Usage |
|---|
git restore <file> | Undo unstaged changes |
git restore --staged <file> | Unstage a file |
git reset <file> | Unstage a file (older method) |
git reset --hard | Reset working directory + history |
git revert <commit> | Create new commit that undoes previous one |
git checkout <commit> | View past version (detached HEAD) |
9. Stashing Work
| Command | Usage |
|---|
git stash | Temporarily save uncommitted changes |
git stash apply | Reapply latest stash |
git stash list | Show all stashes |
git stash drop | Delete a stash |
git stash pop | Apply + delete stash |
10. Tagging Versions
| Command | Usage |
|---|
git tag | List tags |
git tag <name> | Create a lightweight tag |
git tag -a <name> -m "message" | Create annotated tag |
git push --tags | Push tags to remote |
11. Git Ignore
| Command | Usage |
|---|
.gitignore | File that tells Git what to ignore |
git rm -r --cached . | Reapply .gitignore to tracked files |
12. Collaboration / Fixing Conflicts
| Command | Usage |
|---|
| Manual editing | Resolve merge conflicts |
git mergetool | Use merge tool |
git rebase --continue | Continue after conflict fix |
git rebase --abort | Abort rebase |
13. Advanced Tools
| Command | Usage |
|---|
git cherry-pick <commit> | Apply specific commit onto another branch |
git bisect | Find bug-causing commit via binary search |
git blame <file> | Show who edited each line |
git clean -f | Remove untracked files |
git fsck | Verify repo integrity |
git gc | Clean up unnecessary files |
14. Git Submodules
| Command | Usage |
|---|
git submodule add <url> | Add a submodule |
git submodule update | Update submodules |
git submodule init | Initialize submodules |
15. Aliases
| Command | Usage |
|---|
git config --global alias.st status | Create git st alias |
git config --global alias.cm "commit -m" | Shortcut for commits |
Administrator
Latest tech news and coding tips.
Latest tech news and coding tips.