Initaly created by Linus Torvalds in 2005 - now maintained by Junio Hamano.
Google Tech Talk: Linus on Git
Working directory
The project directory containing all project files and folders you which to have under version control.
Repository
The .git
directory where the history of your project is stored.
Commit
A snapshot containing the state of the project at a certain point.
HEAD
Refers to the commit currently checked out in the working directory.
http://www.slideshare.net/lfittl/introduction-to-git-4642204
Need: git and a GitHub or BitBucket account
Don’t forget: 5 free private repos via GitHub Academic account
Optional: Visual git tool, such as Rstudio, GitHub for Mac
Mac with homebrew brew install git
Linux sudo apt-get install git
git config --global user.name "junkka"
git config --global user.email johan.junkka@gmail.com
git config --global core.editor vim
# check config
git config --list
Easiest way to use with a remote server. Instructions
ssh-keygen -t rsa -C "johan.junkka@gmail.com"
cat ~/.ssh/id_rsa.pub
Copy ssh key -> Login to service -> new ssh -> paste ssh key
git init
Initialized empty Git repository in /home/johan/rproj/git-pres/.git/
git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
assets/
index.Rmd
output/
render_pres.R
nothing added to commit but untracked files present (use "git add" to track)
git add README.md
git commit -m "first commit"
Check status
git status
git log
# Overview
git log --stat
Excludes files and directories from git
.gitignore example:
.Rhistory
temp/
echo 'output/' > .gitignore
# Add all files
git add -A
git commit -m "initial all"
# View commit history
git log
# View all currently tracked files
git ls-tree -r master --name-only
git remote add REMOTE-NAME REMOTE-ADRESS
git remote add origin git@github.com:junkka/git-pres.git
First remote push
push all commits with -all
set remote as main upstream repository with -u
git push -u origin --all
# Update file
git commit -am "update"
git push origin master
To view changes between current version and last commited or between versions. Best to use a diff tool. Such as vimdiff, meld, sublimerge etc. Also included in most GUI such as RStudio
For this example we use meld which we set up from the terminal instructions
sudo apt-get install meld
Needs a small startup script
#!/bin/bash
meld "$2" "$5" > /dev/null 2>&1
Add as default diff tool
git config --global diff.tool /usr/local/bin/git-diff.sh
git difftool filename
Accidentally pushed half your harddrive to github?
Force github to reset!
git reset 93c1d75a8 --hard #commithash
git push -f origin # as in force
git clone REPOADRESS
= start from an existing project
git checkout -b BRANCH
= start a new branch
git merge BRANCH
= merge changes from another branch into current
git checkout BRANCH
= checkout an existing branch
git checkout HASH
= checkout a previous commit
git tag v1.0
= add tag to last commit, easier to find
git push origin --tags
= because git doesn’t push tags automatically