Git Cheat Sheet

Install Git in Anaconda Python

conda install -c anaconda git

Use a Repo on Multiple Computers - Example

Create a local test project folder gh_test in /home/rob on Linux PC:

git init

Create a README file.

Create gh_test repo on GitHub.

At command line in local repo:

git remote add origin

Verify remote repo: git remote -v

Push to remote: git push origin master

Create gh_test folder in C:\Users\blueg\Documents on Windows PC.

At command prompt in the gh_test directory:

git clone

NOTE: this created a second ``gh_test`` folder inside ``gh_test``!.

Edit README on Windows machine, committed to Git then pushed to GitHub.

In Linux gh_test folder:

git pull

README updated correctly

Common Git Tasks

List all files being tracked: git ls-files

Remove a directory from tracking: git rm -r one-of-the-directories git commit -m "Remove duplicated directory" git push origin <your-git-branch> (typically ‘master’, but not always)

Remove a remote: git remote rm <remote name>

Git Branching and Merging

List all local and remote branches: git branch -a

Create a new branch and switch to it: git checkout -b <branch name>

Switch back to the original branch: git checkout master

Merge another branch into the current branch: git merge <branch name>

Delete a local branch when no longer needed: git branch -d <branch name>

Delete a remote branch: git push <remote_name> --delete <branch_name>