Martinos Center Why N How, April 5, 2012
..imagine the following scenario:
How do you do it?
Potential problems:
Potential uses for scientists:
Unique features:
A repository contains:
Either create a new repository:
[$] cd ~/mycode [$] git init Initialized empty Git repository in /home/martin/mycode/.git/
Or clone a repository:
[$] git clone git://github.com/schacon/simplegit.git Initialized empty Git repository in /home/martin/simplegit/.git/ remote: Counting objects: 100, done. remote: Compressing objects: 100% (86/86), done. remote: Total 100 (delta 35), reused 0 (delta 0) Receiving objects: 100% (100/100), 9.51 KiB, done. Resolving deltas: 100% (35/35), done. [$] ls -al simplegit total 24 drwxr-xr-x 4 martin martin 4096 Apr 4 14:41 . drwxr-xr-x 9 martin martin 4096 Apr 4 14:41 .. drwxr-xr-x 7 martin martin 4096 Apr 4 14:41 .git -rw-r--r-- 1 martin martin 125 Apr 4 14:41 README -rw-r--r-- 1 martin martin 592 Apr 4 14:41 Rakefile drwxr-xr-x 2 martin martin 4096 Apr 4 14:41 lib
Notice: The .git directory contains the git repository
See the status
[$] cd ~/mycode [$] git status # On branch master # # Initial commit # nothing to commit (create/copy files and use "git add" to track)
Let's add a file
[$] echo "hello git" >> test.txt [$] git add test.txt
See the status again
[$] git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: test.txt
commit all changes
[$] git commit -a -m "my first file" [master (root-commit) cb2ff46] my first file Committer: martin <martin@think.(none)> 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 test.tx
See the log
[$] git log commit cb2ff4663bdc3bf3d38a0ad534dd770656c45f0d Author: martin <martin@think.(none)> Date: Wed Apr 4 15:10:42 2012 -0400 my first file
Make modifications to the file
[$] echo "new content" >> test.txt
See the difference
[$] git diff diff --git a/test.txt b/test.txt index 8d0e412..ab04ca9 100644 --- a/test.txt +++ b/test.txt @@ -1 +1,2 @@ hello git +new content
And again commit the changes
[$] git commit -a -m "more changes" [master cb7fe4f] more changes Committer: martin <martin@think.(none)> 1 files changed, 1 insertions(+), 0 deletions(-)
Let's see what branches are available
[$] git branch * master
so far we only have the master branch
Including our previous two commits (A and B) our repo looks like this:
(A) --- (B) | master | HEAD
Create a new branch
[$] git branch my_branch
Switch to the new branch
[$] git checkout my_branch
Change the file again and commit the changes (commit C)
[$] echo "even more content" >> test.txt [$] git commit -a -m "more content"
Now our repository looks like this
(A) --- (B) ---- (C) | | master my_branch | HEAD
Let's switch back to the master branch
[$] git checkout master
and look at the file
[$] cat test.txt hello git new content
here the file is still the same. The changes we made are in my_branch
We can checkout my_branch again and make more changes.
Finally, we can merge the changes into the master branch
[$] git checkout master [$] git merge my_branch Updating cb7fe4f..6354500 Fast-forward test.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
Now, the master branch includes the changes we made in my_branch
[$] cat test.txt hello git new content even more content
Our repository looks like this
(A) --- (B) ---- (C) -------(D) | | my_branch master | HEAD
Still:
[$] git clone git@github.com:mluessi/gitexample.git
[$] cd gitexample [$] git config user.name "Firstname Lastname" [$] git config user.email myemail@mail.com
Important: Use the same e-mail and name you use on github
[$] git pull
[$] git branch alg_optimization [$] git checkout alg_optimization
Tip: You can do the same using git checkout -b alg_optimization
[$] git push origin alg_optimization
Note: origin is an alias for a remote repo, you can configure them using git remote
This will:
To learn more
If you did not like this talk, fork it, improve it, and create a PR
Table of Contents | t |
---|---|
Exposé | ESC |
Full screen slides | e |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Toggle screen blanking | b |
Show/hide slide context | c |
Notes | 2 |
Help | h |