Git and GitHub commands, explained plainly
The 50 git and GitHub CLI (gh) commands people use every day: what each one does, the options that matter, and examples you can copy.
No commands match.
Set up and clone
- gh auth loginSign in the GitHub CLI to your account
- git cloneCopy a remote repository onto your computer
- git configRead and set Git settings such as your name and email
- git initTurn a folder into a new Git repository
Save changes
- git addStage changes to include in the next commit
- git commitSave staged changes as a snapshot in history
- git diffShow the exact lines that changed
- git mvMove or rename a tracked file
- git rmRemove files from the repository and your folder
- git statusShow what has changed and what is staged
Look at history
- git bisectFind the commit that introduced a bug
- git blameSee who last changed each line of a file
- git logShow the history of commits
- git reflogRecover lost commits from the local movement log
- git showShow one commit, tag or file in detail
Branches and merging
- git branchList, create and delete branches
- git checkoutSwitch branches or restore files (older all-in-one)
- git cherry-pickCopy individual commits onto the current branch
- git mergeCombine another branch into the current one
- git rebaseReplay your commits on top of another base
- git switchMove to another branch
- git tagLabel a commit, such as a release
Share with remotes
- git fetchDownload new commits without changing your files
- git pullFetch from a remote and update your branch
- git pushUpload your commits to a remote
- git remoteManage the other copies of your repository
Undo and tidy up
- git cleanDelete untracked files from the working folder
- git resetMove the branch back and optionally discard changes
- git restoreDiscard edits or un-stage files
- git revertUndo a commit by adding a new one
- git stashShelve uncommitted work to come back to later
Pull requests and issues
- gh issue createOpen a new issue
- gh issue listList issues in a repository
- gh issue viewRead an issue in the terminal
- gh pr checkoutSwitch to the branch of a pull request
- gh pr checksShow the CI check results for a pull request
- gh pr createOpen a pull request from the current branch
- gh pr listList pull requests in a repository
- gh pr mergeMerge a pull request
- gh pr viewShow the details of a pull request
Repos, actions and releases
- gh apiCall the GitHub API directly
- gh browseOpen the repository, an issue or a file in your browser
- gh gist createShare a file or snippet as a GitHub gist
- gh release createPublish a release on GitHub
- gh repo cloneClone a GitHub repository by name
- gh repo createCreate a new repository on GitHub
- gh repo forkMake your own copy of someone else's repository
- gh repo viewShow a repository's description and README
- gh run listList recent GitHub Actions workflow runs
- gh workflow runTrigger a GitHub Actions workflow manually