DEV Community

Kyle Y. Parsotan
Kyle Y. Parsotan

Posted on

Here’s a structured Git command guide from basic advanced, so you can grow step-by-step instead of memorizing random commands.

🟢 Beginner Git Commands (Must Know First)

These are the commands you’ll use every day.


⚙️ Setup (one-time)

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Enter fullscreen mode Exit fullscreen mode

Check config:

git config --list
Enter fullscreen mode Exit fullscreen mode

📁 Start a project

Create new repo:

git init
Enter fullscreen mode Exit fullscreen mode

Clone existing repo:

git clone https://github.com/user/repo.git
Enter fullscreen mode Exit fullscreen mode

📌 Basic workflow (core Git loop)

Check status:

git status
Enter fullscreen mode Exit fullscreen mode

Add files:

git add .
Enter fullscreen mode Exit fullscreen mode

Commit changes:

git commit -m "your message"
Enter fullscreen mode Exit fullscreen mode

Send to GitHub:

git push
Enter fullscreen mode Exit fullscreen mode

Get updates:

git pull
Enter fullscreen mode Exit fullscreen mode

🟡 Intermediate Git Commands (Real Development Work)

This is where Git starts becoming powerful.


🌿 Branching (VERY important)

Create branch:

git branch feature-branch
Enter fullscreen mode Exit fullscreen mode

Switch branch:

git checkout feature-branch
Enter fullscreen mode Exit fullscreen mode

Create + switch at once:

git checkout -b feature-branch
Enter fullscreen mode Exit fullscreen mode

List branches:

git branch
Enter fullscreen mode Exit fullscreen mode

Delete branch:

git branch -d feature-branch
Enter fullscreen mode Exit fullscreen mode

🔀 Merging

Switch to main:

git checkout main
Enter fullscreen mode Exit fullscreen mode

Merge branch:

git merge feature-branch
Enter fullscreen mode Exit fullscreen mode

🌐 Remote repositories

Add remote:

git remote add origin https://github.com/user/repo.git
Enter fullscreen mode Exit fullscreen mode

Check remotes:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Push branch:

git push origin main
Enter fullscreen mode Exit fullscreen mode

Push new branch:

git push -u origin feature-branch
Enter fullscreen mode Exit fullscreen mode

🔄 Sync with remote

Fetch changes (no merge):

git fetch
Enter fullscreen mode Exit fullscreen mode

Pull changes (fetch + merge):

git pull
Enter fullscreen mode Exit fullscreen mode

🔵 Advanced Git Commands (Professional Level)

These are used in real teams, open source, and production systems.


⏪ Undo changes (VERY important)

Undo last commit (keep changes):

git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode

Undo last commit (remove changes):

git reset --hard HEAD~1
Enter fullscreen mode Exit fullscreen mode

Undo file changes:

git checkout -- filename
Enter fullscreen mode Exit fullscreen mode

Restore file from commit:

git restore filename
Enter fullscreen mode Exit fullscreen mode

🧠 Stashing (save work temporarily)

Save changes without committing:

git stash
Enter fullscreen mode Exit fullscreen mode

List stashes:

git stash list
Enter fullscreen mode Exit fullscreen mode

Apply stash:

git stash apply
Enter fullscreen mode Exit fullscreen mode

Remove stash:

git stash drop
Enter fullscreen mode Exit fullscreen mode

🔍 Inspect history

View commits:

git log
Enter fullscreen mode Exit fullscreen mode

Compact log:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Graph view:

git log --graph --oneline --all
Enter fullscreen mode Exit fullscreen mode

See file changes:

git diff
Enter fullscreen mode Exit fullscreen mode

🧩 Rewriting history (advanced)

Edit last commit message:

git commit --amend
Enter fullscreen mode Exit fullscreen mode

Squash commits (interactive):

git rebase -i HEAD~3
Enter fullscreen mode Exit fullscreen mode

🚨 Conflict handling

When merge conflict happens:

git status
Enter fullscreen mode Exit fullscreen mode

Fix files manually → then:

git add .
git commit
Enter fullscreen mode Exit fullscreen mode

🌍 Advanced remote control

Change remote URL:

git remote set-url origin NEW_URL
Enter fullscreen mode Exit fullscreen mode

Remove remote:

git remote remove origin
Enter fullscreen mode Exit fullscreen mode

🧪 Cherry-picking (select commits)

Apply specific commit:

git cherry-pick commit-id
Enter fullscreen mode Exit fullscreen mode

🧭 Rebase (clean history)

Rebase branch:

git rebase main
Enter fullscreen mode Exit fullscreen mode

Continue after conflict:

git rebase --continue
Enter fullscreen mode Exit fullscreen mode

Cancel rebase:

git rebase --abort
Enter fullscreen mode Exit fullscreen mode

🧠 Git mastery workflow (real-world pattern)

This is what developers actually do:

git checkout -b new-feature
# work on code
git add .
git commit -m "add feature"
git push -u origin new-feature
Enter fullscreen mode Exit fullscreen mode

Then open a Pull Request on GitHub.


🚀 Beginner → Advanced roadmap

🟢 Beginner

  • git init
  • add / commit / push / pull
  • status

🟡 Intermediate

  • branches
  • merge
  • remote repos
  • fetch

🔵 Advanced

  • rebase
  • stash
  • cherry-pick
  • reset / revert
  • conflict resolution

💡 Final Advice

Don’t try to memorize everything.

Instead focus on:

branch → commit → push → pull request

Everything else builds on that.

Top comments (0)