# Intro to Git
#### Jayson Harshbarger
# Why version control
```
> ll
mywork
mywork_old
mywork_Feb
mywork_Feb_2014
mywork_Feb_2014_new
mywork_Feb_2014_new_new
```
## Git vs. Whatever
- Not better, different
- No server required, Off-line
- Tracks content not files
- Branches are lightweight
Git workflow
- (git init)
- Edit files
- Review changes (git status)
- Stage changes (git add)
- Commit changes (git commit)
# git init
#### Initialize a new Git repository
- Create a new empty repository in the current folder
- Does not changes any files you have already created
```(bash)
> cd mywork
> git init
Initialized empty Git repository in /Scratch/mywork/.git/
> ll -a
.git/
data/
mydoc.txt
scripts/
```
#### (2. Review changes)
# git status
###
```(bash)
> git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# data/
# mydoc.txt
# scripts/
nothing added to commit but untracked files present (use "git add" to track)
```
#### (2. Review changes)
# git diff
###
```(bash)
> git diff
diff --git a/scripts/myscript.sh b/scripts/myscript.sh
index 9daeafb..038d718 100644
--- a/scripts/myscript.sh
+++ b/scripts/myscript.sh
@@ -1 +1 @@
-test
+testing
```
#### (3. Stage changes)
# git add
###
- Doesn't alter files
- Add only what you want
```(bash)
> git add mydoc.txt scripts/
> git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: mydoc.txt
# new file: scripts/myscript.sh
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# data/
```
#### (4. Commit changes)
# git log
#### a journal of changes
```
> git log
commit 8e2bf4a56ed63c8921ccffa751f6c1783f4b542e
Author: J. Harshbarger
Date: Tue Jun 10 14:32:48 2014 +0900
Second
commit 5053e8cbed15e7e2323fcb15b022847db9863526
Author: J. Harshbarger
Date: Tue Jun 10 14:25:55 2014 +0900
First commit
```
#### (branching)
# git merge
#### Take changes from one branch and merge them with a second.
```
> git checkout master
Switched to branch 'master'
> git merge test
Updating 5053e8c..8e2bf4a
Fast-forward
mydoc.txt | 1 +
scripts/myscript.sh | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
```
# GIT remotes
#### GIT remotes are remote locations where you can mirror changes
- Online (GitHub/Bitbucket)
- Another machine in your network
- Over ssh
```
> git init --bare //filserver/jayson/repos/example.git
Initialized empty Git repository in //filserver/jayson/repos/example.git/
> git remote add filserver //filserver/jayson/repos/example.git
> git push filserver master
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 609 bytes, done.
Total 8 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
To //osc-fs/jayson/repos/example.git
* [new branch] master -> master
```
# MORE
- [Git for the lazy](http://www.spheredev.org/wiki/Git_for_the_lazy)
- [Visual Git Cheat Sheet](http://zrusin.blogspot.com/2007/09/git-cheat-sheet.html)
- [Git for Computer Scientists](http://eagain.net/articles/git-for-computer-scientists/)