Git: an open source, distributed version-control system; GitHub: a platform for hosting and collaborating on Git repositories; commit: a Git object, a snapshot of your entire repository compressed into a SHA; branch: a lightweight movable pointer to a commit; clone: a local version of a repository, including all commits and branches; remote: a common repository on GitHub that all. Contribute to dinskutty/Data-Science-Cheat-Sheet development by creating an account on GitHub.
NOTE: Anything in angle brackets like <this> should be replaced with your own value
Configuration
Global ignore filegit config --global core.excludesfile ~/.gitignore_global
More about ignoring files and sensible defaults for ~/.gitignore
Set the default editorgit config --global core.editor 'nano'
The Basics
git status See what the current situation is
git add . Add all files in the current directory to the index
git add <filename> Add a single file to the index
git rm <filename> Remove a deleted file from the index
git commit -m '<your message>' Commit your changes
git checkout -b <new branch> <existing branch> Create a new branch
git diff <filename> See what has changed in a file since the last commit
git merge --no-ff <branch name> Merge another branch into the current branch
git push <remote> <branch> Push your changes up to the server
git pull <remote> <branch> Pull changes down from the server
Damn useful commands
Selectively add parts of a file to the index
Remove a file from the index while keeping changes
When you realise you have been working on the wrong branch
You can take this further and apply your stash to a new branch:
This creates a new branch starting at the commit at which the stash was created, checks out the branch, and applies the stash.
Undo last commit (keep changed files)
(Add further ^ to step back more than 1 commit)
Undo last commit (discard changed files)
(Add further ^ to step back more than 1 commit)
Undo a specific commit
Identify the hash of the commit
Revert the commit
This produces another commit. To exit Vim after adding the commit message,
If you just want the modified files but not the auto-commit
Ignore files that already exist in the repository
You won’t be able to update that file until you do:
Delete a local branch
Track a remote branch
Track a remote branch (including tags)
Delete a remote branch
Recover a deleted branch
Where
<sha>is the tip of your deleted branch (usegitrefto find the hash)Generate a changelog
Safe Branching Model
Two main branches:
Create a feature branch:
Incorporate a finished feature into develop:
Create a release branch:
Modify a file in some way (ie change version number)
This is a good time to update the changelog with an overview of features and bugfixes in this release.
Finishing a release branch:
If your project has a package.json, a better way to bump the version number and create a tag is to use:
Merge changes back into develop:
Creating a hotfix branch
A hotfix is a bugfix that must be urgently pushed to production. We want to avoid introducing further bugs from untested code, so we only work on the fix from the master branch:
Modify a file in some way
Finishing a hotfix branch:
Merge changes back into develop:
The one exception to the rule here is that, when a release branch currently exists, the hotfix changes need to be merged into that release branch, instead of develop.

Deployment
Set up the folder structure on the server:
Initialise the repo:
Add a post receive hook to make the changes live:

Make the hook executable:
Add the remote to your local repo:
You are now ready to push. The first time, you will need to add the branch:
After that, you can just:
When working with GitHub Repositories, the Github.com website provides an excellent interface for working with Issues, Pull Requests, and Repositories. Of course, when committing file changes and merging branches, you still use the git CLI. However, this requires context switching between CLI and browser. Luckily, the GitHub CLI (gh) offers a full command-line / terminal experience for working with GitHub. Here’s a cheat sheet I’ve put together that showcases many of the GitHub CLI commands to help you be more productive at the command-line as you perform operations against your GitHub Pull Requests, Issues, and Repositories!
The GitHub CLI Cheat Sheet is available in a couple different formats for download:
Git Cheat Sheet Available – I have also created a Git cheat sheet you can download too. Using both of these cheat sheets will definitely help you level-up your Git and GitHub CLI game!
Feel free to print this GitHub CLI cheat sheet, or save it to your desktop, for easy access to common GitHub CLI commands. This way you will be able to stay more productive by not needing to look up these commands so often as you’re working with your GitHub Pull Requests, Issues, and Repositories from the command-line.
Using Github For Documentation
Additionally, you can purchase it printed on mugs, stickers, and more!
Git Commands List
- Purchase GitHub CLI cheat sheet stickers!
- Purchase GitHub CLI cheat sheet printed on a mug!
Github Cheat Sheet Pdf
Happy working with your GitHub pull requests, issues, and repositories using the command-line!
Chris is the Founder of Build5Nines.com and a Microsoft MVP in Azure & IoT with 20 years of experience designing and building Cloud & Enterprise systems. He is also a Microsoft Certified: Azure Solutions Architect, developer, Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
