GitHub is the world’s most popular platform for hosting and collaborating on code. Developers use it to manage projects, track changes, and work together seamlessly across teams. While GitHub’s web interface is beginner-friendly, relying only on the UI can slow you down. Mastering GitHub commands from the command line (CLI) makes you faster, gives you more control, and is an essential skill for professional developers, DevOps engineers, and open-source contributors.
In this guide, we’ll cover everything you need to know about using GitHub from the command line — from setup to advanced branch management. By the end, you’ll be able to clone, push, pull, and manage repositories without touching the GitHub website.
Download and install Git for your OS:
Check installation:
git --version
Set up your name and email (used in commits):
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
Instead of typing your password every time, set up SSH keys:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Add the key to GitHub under Settings → SSH and GPG keys.
# Initialize a new Git repository
git init
# Clone a repository from GitHub
git clone <repo_url>
# Check the status of files (modified, staged, untracked)
git status
# Stage all changes
git add .
# Commit staged changes
git commit -m "commit message"
# Push changes to the remote repository
git push origin main
# Pull latest changes from remote repository
git pull origin main
# Create and switch to a new branch
git checkout -b branch_name
# Switch to an existing branch
git checkout branch_name
# Merge a branch into the current branch
git merge branch_name
# Show remote connections
git remote -v
git clone https://github.com/username/repo.git
cd repo
git checkout -b my-feature
git add .
git commit -m "Added new feature"
git push origin my-feature
git pull origin main
git push origin --delete my-feature
git branch -d my-feature
Conflicts happen when two people edit the same file.
Git marks conflicts like this:
<<<<<<< HEAD
Your changes
=======
Main branch changes
>>>>>>> main
Fix manually, then:
git add .
git commit -m "Resolved conflicts"
Happens when you checkout a commit instead of a branch.
Fix: move back to a branch.
git checkout main
git pull origin main
git fetch origin
git branch
git branch -r
git log --oneline
git log --oneline --graph --all
git branch -m new-branch-name
# Unstage a file (remove from git add) git reset HEAD filename # Undo last commit but keep changes staged git reset --soft HEAD~1 # Undo last commit and delete changes git reset --hard HEAD~1
# Force push your current branch to remote (dangerous)
git push origin HEAD --force
# Safer option (doesn’t overwrite others’ work)
git push origin HEAD --force-with-lease
git branch --merged main | grep -v "main" | xargs git branch -d
Mastering GitHub from the command line is one of the most valuable skills you can learn as a developer. It allows you to work faster, collaborate effectively, and handle projects like a pro. Whether you’re managing personal projects or contributing to open source, these commands form the foundation of your workflow.
As you grow in your coding journey, it’s equally important to choose the right programming language to invest your time in. If you’re still deciding, check out this guide on the best programming languages to learn in 2025.
Start small: clone, edit, commit, push. With daily practice, these commands will become second nature — and you’ll never have to rely solely on the GitHub UI again.
September 4, 2025 • 5 minute(s) read
August 26, 2025 • 11 minute(s) read
August 11, 2025 • 4 minute(s) read
June 12, 2025 • 3 minute(s) read
May 22, 2025 • 4 minute(s) read
April 27, 2025 • 5 minute(s) read