Skip to main content
Git Commands from Beginner to Advanced: Complete Git Cheat Sheet for Developers
0
Technology

Git Commands from Beginner to Advanced: Complete Git Cheat Sheet for Developers

Learn Git commands from beginner to advanced level with practical examples. Master repository creation, branching, merging, rebasing, stashing, remote repositories, and advanced Git workflows.

📅 Published Jun 16, 2026 🔄 Updated Jun 16, 2026 ⏱️3 min read👁3 views
Read in:

Git Commands from Beginner to Advanced

Git is the most widely used version control system that helps developers track code changes, collaborate with teams, and manage software projects efficiently. This guide covers essential Git commands from beginner to advanced levels.

Beginner Git Commands

1. Check Git Version

git --version

2. Configure Username

git config --global user.name "Your Name"

3. Configure Email

git config --global user.email "you@example.com"

4. Initialize a Repository

git init

5. Clone a Repository

git clone <repository-url>

6. Check Repository Status

git status

7. Add Files to Staging Area

git add file.txt

Add all files:

git add .

8. Commit Changes

git commit -m "Initial commit"

9. View Commit History

git log

10. Create a New Branch

git branch feature-branch

11. Switch Branch

git checkout feature-branch

Or:

git switch feature-branch

12. Create and Switch Branch

git checkout -b feature-branch

13. View Branches

git branch

14. Merge Branches

git checkout main
git merge feature-branch

15. Delete Branch

git branch -d feature-branch

16. Add Remote Repository

git remote add origin <repository-url>

17. Push Changes

git push origin main

18. Pull Latest Changes

git pull origin main

19. Fetch Updates

git fetch

20. View Remote Repositories

git remote -v

Advanced Git Commands

21. Rebase Branch

git rebase main

22. Interactive Rebase

git rebase -i HEAD~5

23. Cherry-Pick Commit

git cherry-pick <commit-hash>

24. Stash Changes

git stash

25. View Stashes

git stash list

26. Apply Stash

git stash apply

27. Pop Stash

git stash pop

28. Reset Commit (Soft)

git reset --soft HEAD~1

29. Reset Commit (Hard)

git reset --hard HEAD~1

30. Revert Commit

git revert <commit-hash>

31. View Differences

git diff

32. View Staged Changes

git diff --staged

33. Tag a Release

git tag v1.0.0

Push tags:

git push origin --tags

34. Show Reference Log

git reflog

35. Clean Untracked Files

git clean -fd

Expert-Level Git Commands

36. Bisect for Bug Detection

git bisect start
git bisect bad
git bisect good <commit-hash>

37. Squash Commits

git rebase -i HEAD~5

38. Amend Last Commit

git commit --amend

39. View Commit Graph

git log --oneline --graph --all

40. Force Push (Use Carefully)

git push --force-with-lease

41. Track Remote Branch

git checkout --track origin/feature-branch

42. Find Author Information

git blame file.txt

43. Search Commit History

git log --grep="bug fix"

44. Archive Repository

git archive --format zip --output project.zip HEAD

45. Remove File from Git Tracking

git rm --cached file.txt

Git Fetch vs Git Pull

FeatureGit FetchGit Pull
PurposeDownloads latest changes from the remote repositoryDownloads changes and merges them into the current branch
Changes to Local BranchDoes not modify your working branchAutomatically updates your current branch
SafetySafer because you can review changes before mergingFaster but may create merge conflicts immediately

Git Merge vs Git Rebase

FeatureGit MergeGit Rebase
Commit HistoryPreserves complete branch historyCreates a cleaner, linear history
New CommitCreates a merge commitDoes not create a merge commit
Team CollaborationSafer for shared branchesBetter for personal feature branches

Git Reset vs Git Revert

FeatureGit ResetGit Revert
History ImpactRemoves commits from historyCreates a new commit that undoes changes
Safe for Shared BranchesNoYes
Use CaseLocal undo operationsUndo changes in public repositories
Git Workflow Summary

  1. Initialize or clone a repository.
  2. Create a feature branch.
  3. Make changes and stage files.
  4. Commit changes with meaningful messages.
  5. Push branch to remote repository.
  6. Create a pull request.
  7. Merge approved changes into the main branch.
  8. Pull latest updates regularly.

📂 Categories

🏷️ Tags

💬 Frequently Asked Questions

What is Git and why is it used?

Git is a distributed version control system that helps developers track code changes, collaborate with teams, manage project history, and safely revert changes when needed.

What is the difference between Git Fetch and Git Pull?

git fetch downloads changes from a remote repository without merging them, while git pull downloads and automatically merges those changes into the current branch.

When should I use Git Rebase instead of Merge?

Use Git Rebase when you want a cleaner and linear commit history. Use Merge when you want to preserve the complete branch history and collaboration context.

How can I undo my last Git commit?

You can undo the last commit while keeping changes using: git reset --soft HEAD~1 To completely remove the commit and changes: git reset --hard HEAD~1

What is Git Stash used for?

Git Stash temporarily saves uncommitted changes so you can switch branches or work on another task without committing unfinished work.

About the author Vivek Verma

Software Developer

0Blogs
0Followers

Discussion

AnonymousGuest