lexington®
Use code LEX35 at checkout
 
  
  
  
 7k+ customers.
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.
Published on August 5, 2025 by Michael AndreuzzaGit 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 initUse 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.gitOften your first step when working with existing code.
Staging and committing
git status
Check which files have changed and what’s staged.
git statusHelpful before every commit.
git add
Stage files for a commit.
git add .         # Add everything
git add file.txt  # Add a specific fileOnly 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 mainPushes your changes to the remote main branch.
git pull
Fetch and merge updates from GitHub into your local branch.
git pull origin mainKeeps your local repo up to date with teammates’ changes.
git fetch
Download new data from GitHub without merging it yet.
git fetch originLets 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 branchgit checkout or git switch
Switch between branches.
git checkout branch-name
# or
git switch branch-namegit 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-pageUseful when starting new work.
git merge
Merge one branch into another.
git merge feature/new-pageBrings changes from one branch into your current one.
Undoing and fixing
git stash
Temporarily save uncommitted changes.
git stashUse 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 filegit restore
Restore a file to the last committed version.
git restore file.txtDiscard unwanted changes in a specific file.
git rebase -i
Interactively rebase commits to clean up history.
git rebase -i HEAD~3This 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 reflogA 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 logAdd --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 commitUseful 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.0Helpful for tracking releases. Check out the full guide to Git tags →
Remotes and repositories
git remote -v
List the current remote URLs.
git remote -vVerify 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.gitCommon 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 createThis 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