Git CLI Mastery: Why Command Line Beats GitHub Desktop
Inspired by a viral X thread, discover the 28 essential git commands that empower efficient version control without relying on graphical interfaces like GitHub Desktop.
Why Choose Git CLI Over GitHub Desktop?
While GitHub Desktop offers a simple graphical interface for basic operations, the command-line interface (CLI) provides unparalleled power, flexibility, and efficiency. Here's why mastering git commands is superior:
- Full Control: CLI allows precise operations that GUIs often abstract away, helping you understand git's inner workings and fix complex issues.
- Scriptability: Easily automate workflows in scripts or CI/CD pipelines—impossible with a GUI.
- Portability: Works everywhere, from local machines to remote servers, without installing heavy applications.
- Speed: Faster for experienced users; no waiting for GUI elements to load.
- Advanced Features: Access to powerful tools like rebase, bisect, and reflog that GUIs may not support fully or intuitively.
- Learning Curve Pays Off: Once learned, these 28 commands cover 99% of your needs, making you more productive than GUI-dependent workflows.
This guide draws from a thought-provoking X post by Dmitrii Kovanikov (@ChShersh), who sparked a lively debate on the merits of CLI over Desktop apps.
The Essential 28 Git Commands
Below is the curated list of 28 commands that make git efficient. Each is explained with its purpose and usage.
git clone
Clones a repository from a remote URL to your local machine.
git clone <repository-url> git log
Displays the commit history for the current branch.
git log git status
Shows the current state of your working directory and staging area.
git status git add .
Adds all changes in the current directory to the staging area.
git add . git add <path>
Adds a specific file or directory to the staging area.
git add <path> git diff
Shows differences between working directory and staging area.
git diff git commit -m "message"
Commits staged changes with a message.
git commit -m "Short description" git commit -am "message"
Adds tracked changes and commits in one step.
git commit -am "Short description" git commit -a --amend
Amends the last commit with new staged changes.
git commit -a --amend git push
Pushes local commits to the remote branch.
git push git push -u origin branch
Pushes and sets upstream tracking for a new branch.
git push -u origin branch-name git switch branch
Switches to an existing branch.
git switch branch-name git switch -c branch
Creates and switches to a new branch.
git switch -c branch-name git branch -D branch
Force-deletes a local branch.
git branch -D branch-name git pull --ff-only
Pulls only if fast-forward is possible.
git pull --ff-only origin <branch> git fetch
Fetches updates without merging.
git fetch origin main git reset --hard
Resets branch to match remote, discarding changes.
git reset --hard origin/main git checkout -- .
Discards all local changes.
git checkout -- . git rebase
Rebases current branch onto another.
git rebase origin/main git rebase -i
Interactive rebase for editing recent commits.
git rebase -i HEAD~<N> git rebase --onto
Advanced rebase to transplant commits.
git rebase --onto <newbase> <oldbase> git cherry-pick
Applies a specific commit.
git cherry-pick <hash> git stash
Temporarily shelves changes.
git stash git stash pop
Reapplies the latest stashed changes.
git stash pop git stash list
Lists all stashed changes.
git stash list git remote add upstream
Adds an additional remote repository.
git remote add upstream <url> git bisect
Binary search to find a bug-introducing commit.
git bisect start / good / bad git reflog
Shows history of reference updates for recovery.
git reflog Getting Started
Install git, create a test repo, and practice these commands. The CLI gives you full power over version control that no GUI can match.
Original inspiration: X thread by @ChShersh