From Dave's wiki
Jump to navigation Jump to search

Git is an open source distributed version control system.

Getting started

A useful minimum set of commands for Everyday Git ->

See my post on Git ->

Set up key ->

Notes taken from

#to initialize a Git repository
git init
#check current state
git status
#start tracking changes made to octocat.txt
#to add multiple files
#git add one.txt two.txt
git add octocat.txt
#to store our staged changes
git commit -m "Add cute octocat story"
#check log
git log
#push our local repo to the GitHub server
git remote add origin
#if you want to remove origin
git remote rm origin
#specify where to put our commits
git push -u origin master
#check for changes on our GitHub repository
git pull origin master
#look at what is different from our last commit
#diff between last commit and what's been staged
#git diff --staged
git diff HEAD
#unstage files
git reset octofamily/octodog.txt

The default Git branch is master. Branches allow you to work on and switch between different versions of your project.

#to delete a branch
git branch -d clean_up
#create a file called .gitignore in the root
#and add stuff you don't want tracked

Common tasks

Guide to branching and merging

Viewing the commit history

Checking a specific commit

git log
git show <revhash>

Git difference between two commits

git log
git diff 2879cb83af7fe43c741f6ff298b22d4f7f267bc8 9d9f2f406564d6ed76b0427d5223c187570c8d29

Unmodifying a Modified File (see

git checkout -- some_file.txt

Throw out all changes (

git checkout -f
git reset --HARD

Cloning with SSH

#git clone ssh://<user>/<repository name>.git
git clone ssh://

git clean -fd

Hard delete unpublished commits

git reset --hard 0d1d7fc32


Rebase is one of two Git utilities that specialises in integrating changes from one branch onto another. The other change integration utility is git merge. Rebasing is the process of moving or combining a sequence of commits to a new base commit. From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base. It's very important to understand that even though the branch looks the same, it's composed of entirely new commits.

Update a fork

git clone
cd scRNA-seq_notes/

# add remote as upstream
git remote add upstream

# show remote
git remote

# fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:
git fetch upstream

# check which branch you are on
git branch
* master

# switch to master branch if you are not on master
git checkout master

# rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:
git rebase upstream/master

# push to origin remote
git push origin master


Add all

git add -A

Stage all tracked files

#-a stage all modified files
git commit -a -m 'message'


Configure name and email

git config --global "Dave Tang"
git config --global ""

List configurations

git config -l Tang

Using Git with terminal colours

git config --global color.ui true


To use ssh authentication change "" to "", for example:

git clone
git clone


GitHub Standard Fork & Pull Request Workflow ->

GitHub pages

git clone
#or using ssh key
#git clone
echo "Hello World" > index.html
git add --all
git commit -m "Initial commit"
git push

Then visit:

Documentation here ->

Using Jekyll with Pages ->

Installing Ruby

tar -xzf ruby-2.1.1.tar.gz
cd ruby-2.1.1/
sudo make install

Installing Bundler

sudo gem install bundler

Installing GitHub Pages Ruby Gem

sudo gem install github-pages

Create Gemfile (placed in the root directory of your repository), which contains:

source ''
gem 'github-pages'

Then run:

bundle install