Gary's Notebook


Git Cheatsheet: Commands That Actually Work

Posted on 2019-02-20

This is a constantly updating notebook on git commands that actually work for me.

First, some vocabulary to help you read the docs and my notes:

<remote>: name of a remote respository, it could be <origin> or <upstream>.
<origin>: name of your own remote github repository, can be named anything but convention is to name it origin.
<upstream>: name of someone else's remote github repository that you cloned from, can be named anything but convention is to name it upstream.
<your_branch_name>: you can find this by typing "git branch" in the terminal.
<feature_branch>: name of a new branch (that is not master branch) you want.

Working with a Github repository

Add a remote repository:
git remote add <nickname> <url> (Note: You find the url by clicking on the "clone or download" on the repository's page)

Push to remote:
git push -u <nickname> master

Fetch a remote and merge it with your own:
git pull <remote>

Working with Branches

Create a new branch:
git branch <feature_branch>

Switch to the feature branch:
git checkout <feature_branch>

To clone a specific branch:
git clone --single-branch --branch <feature_branch> <remote>

List all git branch:
git branch -a

Working with Git Commits

Undo git add:
git reset