23 GitHub commands every developer should know
A practical guide to 23 essential Git and GitHub commands for everyday development. Learn how to clone, commit, push, merge, and more.
Git is the foundation of modern software collaboration, and GitHub is where that work gets shared, reviewed, and deployed. Whether you’re working solo or as part of a team, there are a handful of commands you’ll use over and over again.
This post distills 23 essential Git and GitHub commands, focusing on those you’ll use most frequently in your daily development workflow. Let’s dive in and master the tools that empower seamless collaboration and efficient version control.
Initializing and cloning
git init
Start a new local Git repository.
git init
Use this when you want to start tracking a folder with Git.
git clone
Copy a remote repository (like one from GitHub) to your local machine.
git clone https://github.com/your-user/repo-name.git
Often your first step when working with existing code.
Staging and committing
git status
Check which files have changed and what’s staged.
git status
Helpful before every commit.
git add
Stage files for a commit.
git add . # Add everything
git add file.txt # Add a specific file
Only staged files will be included in the commit.
git commit
Commit staged changes with a message.
git commit -m "Describe what you changed"
Make your messages meaningful and consistent.
Pushing and pulling
git push
Send local commits to GitHub.
git push origin main
Pushes your changes to the remote main
branch.
git pull
Fetch and merge updates from GitHub into your local branch.
git pull origin main
Keeps your local repo up to date with teammates’ changes.
git fetch
Download new data from GitHub without merging it yet.
git fetch origin
Lets you inspect what’s changed before integrating it.
Working with branches
git branch
List, create, or delete branches.
git branch # List branches
git branch new-branch # Create a branch
git checkout
or git switch
Switch between branches.
git checkout branch-name
# or
git switch branch-name
git switch
is preferred in newer Git versions.
git checkout -b
Create and switch to a new branch in one step.
git checkout -b feature/new-page
Useful when starting new work.
git merge
Merge one branch into another.
git merge feature/new-page
Brings changes from one branch into your current one.
Undoing and fixing
git stash
Temporarily save uncommitted changes.
git stash
Use this to switch branches without losing your work.
git reset
Undo commits or staged files.
git reset HEAD~1 # Undo last commit
git reset file.txt # Unstage a file
git restore
Restore a file to the last committed version.
git restore file.txt
Discard unwanted changes in a specific file.
git rebase -i
Interactively rebase commits to clean up history.
git rebase -i HEAD~3
This powerful command allows you to squash, reorder, edit, or delete commits, creating a cleaner and more linear project history before pushing to a shared repository.
git reflog
Show a log of where HEAD and other references have been.
git reflog
A lifesaver for recovering lost commits or branches, as it tracks almost every change to your repository.
Inspecting and reviewing
git log
View your commit history.
git log
Add --oneline
for a more compact view.
git diff
See what has changed.
git diff # Show changes not yet staged
git diff --staged # Show changes between staging area and last commit
Useful before committing or pushing changes.
Tagging and releases
git tag
Mark a specific commit with a version or release label.
git tag v1.0.0
git push origin v1.0.0
Helpful for tracking releases. Check out the full guide to Git tags →
Remotes and repositories
git remote -v
List the current remote URLs.
git remote -v
Verify where your code is being pushed and pulled from.
git remote add
Add a new remote repository.
git remote add origin https://github.com/user/repo.git
Common when connecting a local repo to GitHub for the first time.
git config
Get and set repository or global options.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Essential for setting up your Git identity and customizing your Git environment.
Bonus: GitHub CLI commands
If you’re using the GitHub CLI (gh
), here are a few you’ll use often:
gh repo clone owner/repo
gh issue create
gh pr create
This tool integrates directly with GitHub for managing repos, issues, and pull requests from the terminal.
Conclusion
Mastering Git and GitHub isn’t about memorizing hundreds of commands — it’s about understanding the key commands that power your daily workflow. These 23 commands form the backbone of most projects, from cloning and committing to merging and releasing, empowering you to navigate your codebase with confidence and collaborate effectively. What are your go-to Git commands? Share your favorites in the comments below!
/Michael Andreuzza