DEV Community

Abinash Behera
Abinash Behera

Posted on

From Git Beginner to Advanced: The Complete Guide Every Developer Should Know

A practical guide to mastering Git—from your first commit to advanced collaboration and repository management.

Introduction

Whether you're building personal projects, contributing to open source, or working in a professional software team, Git is one of the most important tools you'll use every day.

Unfortunately, many developers only know a handful of commands like git add, git commit, and git push, while Git offers far more powerful features that simplify collaboration, debugging, and version management.

In this guide, we'll take a step-by-step journey from Git basics to advanced workflows, covering the commands and concepts every developer should know.

Let's get started.


1. What is Git?

Git is a distributed version control system that tracks changes in your source code.

It allows you to:

  • Track every code change
  • Collaborate with teams
  • Restore previous versions
  • Experiment safely using branches

2. Installing Git

Download Git:

https://git-scm.com/

Verify installation:

git --version
Enter fullscreen mode Exit fullscreen mode

3. Configure Git

Before using Git, configure your identity.

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

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

Check your configuration:

git config --list
Enter fullscreen mode Exit fullscreen mode

4. Create Your First Repository

Initialize Git inside a project.

git init
Enter fullscreen mode Exit fullscreen mode

Check repository status.

git status
Enter fullscreen mode Exit fullscreen mode

5. Tracking Files

Stage files:

git add .
Enter fullscreen mode Exit fullscreen mode

or

git add filename.cs
Enter fullscreen mode Exit fullscreen mode

Commit your changes.

git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

6. Understanding the Git Workflow

Git has three main areas:

Working Directory

Staging Area

Repository

Understanding this workflow helps avoid many beginner mistakes.


7. Viewing Commit History

git log
Enter fullscreen mode Exit fullscreen mode

Compact version:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Beautiful graph:

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

8. Branching

Create a branch.

git branch feature-login
Enter fullscreen mode Exit fullscreen mode

Switch branches.

git switch feature-login
Enter fullscreen mode Exit fullscreen mode

Or

git checkout feature-login
Enter fullscreen mode Exit fullscreen mode

9. Merging Branches

Merge your feature into main.

git checkout main

git merge feature-login
Enter fullscreen mode Exit fullscreen mode

10. Working with GitHub

Connect your repository.

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

Push code.

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Clone a repository.

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

11. Pulling Latest Changes

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Fetch only:

git fetch
Enter fullscreen mode Exit fullscreen mode

Difference:

  • fetch downloads changes
  • pull downloads and merges

12. Undo Mistakes

Unstage files.

git restore --staged file.cs
Enter fullscreen mode Exit fullscreen mode

Discard changes.

git restore file.cs
Enter fullscreen mode Exit fullscreen mode

Undo last commit.

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

13. Git Stash

Temporarily save unfinished work.

git stash
Enter fullscreen mode Exit fullscreen mode

Restore it.

git stash pop
Enter fullscreen mode Exit fullscreen mode

List stashes.

git stash list
Enter fullscreen mode Exit fullscreen mode

14. Resolving Merge Conflicts

Conflicts happen when two branches modify the same code.

Steps:

  • Open conflicted file
  • Resolve differences
  • Save file
  • Stage changes
  • Commit merge

15. Cherry Pick

Copy one commit from another branch.

git cherry-pick commit_hash
Enter fullscreen mode Exit fullscreen mode

Perfect for bug fixes.


16. Interactive Rebase

Clean commit history.

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

Useful for:

  • Squashing commits
  • Renaming commits
  • Reordering history

17. Git Tags

Create release versions.

git tag v1.0.0
Enter fullscreen mode Exit fullscreen mode

Push tags.

git push origin --tags
Enter fullscreen mode Exit fullscreen mode

18. Git Ignore

Ignore unnecessary files.

Example:

bin/
obj/

.vs/

node_modules/

.env
Enter fullscreen mode Exit fullscreen mode

19. Useful Git Aliases

git config --global alias.st status

git config --global alias.co checkout

git config --global alias.br branch

git config --global alias.cm commit
Enter fullscreen mode Exit fullscreen mode

Now simply run:

git st

git co

git br
Enter fullscreen mode Exit fullscreen mode

20. Advanced Git Features

Explore these powerful capabilities:

  • Rebase
  • Bisect
  • Worktrees
  • Reflog
  • Hooks
  • Submodules
  • Sparse Checkout
  • Git LFS
  • Signed Commits
  • GitHub Actions Integration

Common Git Commands Cheat Sheet

git init
git clone
git status
git add .
git commit -m ""
git push
git pull
git fetch
git branch
git switch
git checkout
git merge
git rebase
git stash
git reset
git restore
git revert
git tag
git cherry-pick
git log --oneline
Enter fullscreen mode Exit fullscreen mode

Best Practices

✅ Commit frequently

✅ Write meaningful commit messages

✅ Keep branches focused

✅ Pull before pushing

✅ Never commit secrets

✅ Use .gitignore properly

✅ Review changes before committing


Final Thoughts

Git is much more than a tool for saving code—it's the foundation of modern software development. Mastering Git means writing code with confidence, collaborating effectively, and recovering from mistakes when they happen.

Don't try to learn everything at once. Start with the basics, practice daily, and gradually explore advanced features like branching, rebasing, cherry-picking, and Git hooks. Over time, these skills will become second nature and significantly improve your development workflow.

Happy coding! 🚀


If you found this guide helpful, let me know which Git command you use the most—or which advanced feature you're excited to learn next!

Top comments (0)