HomeProjects
1+ Years Experience

Mastering Git: The Complete Command Line Guide

Git & GitHubJan 16, 202615 min read

Git is an essential tool for every modern developer. While GUI tools exist, mastering the command line gives you ultimate control and speed. This guide serves as a complete reference for the most common and powerful Git commands you'll use daily.

Git vs SVN: Why Git?

SVN (Centralized)

  • One central server
  • Network required for commits
  • Slow branching & merging

Git (Distributed)

  • Every dev has full history
  • Commit locally, push later
  • Blazing fast branching

1. Setup & Config

bash
$ git init

Initialize a new local repository

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

Set your global username

bash
$ git config --global user.email "email@example.com"

Set your global email

bash
$ git config --list

List all global and local configurations

2. Basic Workflow

bash
$ git add <file>

Add a specific file to the staging area

bash
$ git add .

Add all changed files to staging

bash
$ git commit -m "commit message"

Commit staged changes with a message

bash
$ git status

Check the status of your working directory

bash
$ git log

View commit history

bash
$ git diff

Show differences between working directory and staging

3. Branching & Merging

bash
$ git branch

List all local branches

bash
$ git branch <name>

Create a new branch

bash
$ git checkout <name>

Switch to a specific branch

bash
$ git checkout -b <name>

Create and switch to a new branch

bash
$ git merge <branch>

Merge a branch into the current one

bash
$ git branch -d <name>

Delete a local branch

4. Working with Remotes

bash
$ git clone <url>

Clone an existing repository

bash
$ git remote add origin <url>

Link local repo to a remote server

bash
$ git push origin <branch>

Push local commits to remote

bash
$ git pull

Fetch and merge changes from remote

bash
$ git fetch

Download changes from remote without merging

5. Advanced & Undo

bash
$ git reset <file>

Unstage a file while keeping its changes

bash
$ git checkout -- <file>

Discard changes in working directory

bash
$ git revert <commit>

Create a new commit that undoes a previous one

bash
$ git stash

Temporarily save uncommitted changes

bash
$ git stash pop

Apply and remove stashed changes

bash
$ git rebase <branch>

Apply commits on top of another base tip

Conclusion

Mastering these commands will significantly improve your productivity. Remember, Git is a safety net; the more you understand how it works under the hood, the more confident you'll be in managing your codebase and collaborating with others.

Have an idea?

Let's Connect

Copyright © 2025 Bibek Shah