Skip to main content

Command Palette

Search for a command to run...

39 Git Commands You Must Know.

Updated
3 min read
39 Git Commands You Must Know.
A

Cloud & DevOps Engineer | Ex-Virtusan | AWS | Terraform | Jenkins | Docker | Kubernetes |

Here are 39 Git commands every engineer should know.

Not just DevOps ~ almost every field in tech uses Git.

Because everything lives in Git.

Your code.
Your infrastructure.
Your pipelines.
Your rollbacks.
Your AI experiments and models.

That’s when real Git knowledge starts to matter.
Because Git isn’t just version control.

It’s what saves you when something inevitably breaks.

So if you’re in tech ~ learn Git beyond the basics.


📌 1️⃣ Basic Git Commands

1. Initialize Repository

git init

Creates a new Git repository in the current directory.

2. Clone Repository

git clone https://github.com/user/repo.git

Copies a remote repository to your local machine.

3. Check Status

git status

Shows working directory and staging area state.

4. Add File to Staging

git add file.txt

5. Commit Changes

git commit -m "Initial commit"

6. Configure Git User

git config --global user.name "Your Name"
git config --global user.email "your@email.com"

7. View Commit History

git log

8. Show Commit Details

git show <commit-hash>

9. View Differences

git diff

10. Unstage File / Reset

git reset HEAD file.txt

🌿 2️⃣ Branching & Merging

11. Create Branch

git branch feature-branch

12. Switch Branch (Legacy)

git checkout feature-branch
git switch feature-branch

14. Merge Branch

git merge feature-branch

15. Rebase Branch

git rebase main

16. Cherry-pick Commit

git cherry-pick <commit-hash>

🌍 3️⃣ Remote Repository Commands

17. Add Remote

git remote add origin https://github.com/user/repo.git

18. Push Changes

git push origin main

19. Pull Changes

git pull origin main

20. Fetch Changes

git fetch origin

21. View Remote URLs

git remote -v

📦 4️⃣ Stashing & Cleaning

22. Stash Changes

git stash

23. Apply & Remove Stash

git stash pop

24. List Stashes

git stash list

25. Clean Untracked Files

git clean -f

🏷 5️⃣ Tagging (Release Management)

26. Create Annotated Tag

git tag -a v1.0 -m "Version 1.0"

27. Delete Tag

git tag -d v1.0

28. Push Tags

git push origin --tags

🔍 6️⃣ Debugging & Recovery

git bisect start

Identifies the commit that introduced a bug.

30. Track Line-Level Changes

git blame file.txt

31. Recover Lost Commits

git reflog

Helps restore commits after accidental reset or rebase.


📁 7️⃣ Repository Management

32. Add Submodule

git submodule add <repo-url>

33. Create Repository Archive

git archive --format=zip HEAD > repo.zip

34. Optimize Repository

git gc

🐙 8️⃣ GitHub CLI (gh) Commands

Modern DevOps teams heavily use GitHub CLI for automation and faster workflows.

35. Authenticate GitHub CLI

gh auth login

36. Clone Repo via GitHub CLI

gh repo clone user/repo

37. Create New GitHub Repository

gh repo create

38. List Issues

gh issue list

39. Create Pull Request

gh pr create