ls import sha # Our first commit data1 = 'This is the start of my paper2.' meta1 = 'date: 1/1/12' hash1 = sha.sha(data1 + meta1).hexdigest() print 'Hash:', hash1 # Our second commit, linked to the first data2 = 'Some more text in my paper...' meta2 = 'date: 1/2/12' # Note we add the parent hash here! hash2 = sha.sha(data2 + meta2 + hash1).hexdigest() print 'Hash:', hash2 %%bash git config --global user.name "Fernando Perez" git config --global user.email "Fernando.Perez@berkeley.edu" %%bash # Put here your preferred editor. If this is not set, git will honor # the $EDITOR environment variable git config --global core.editor /usr/bin/jed # my lightweight unix editor # On Windows Notepad will do in a pinch, I recommend Notepad++ as a free alternative # On the mac, you can set nano or emacs as a basic option # And while we're at it, we also turn on the use of color, which is very useful git config --global color.ui "auto" %%bash git config --global credential.helper cache # Set the cache to timeout after 2 hours (setting is in seconds) git config --global credential.helper 'cache --timeout=7200' !git %%bash rm -rf test git init test %%bash cd test ls %%bash cd test ls -la %%bash cd test ls -l .git %%bash cd test echo "My first bit of text" > file1.txt %%bash cd test git add file1.txt %%bash cd test git status %%bash cd test git commit -a -m"This is our first commit" %%bash cd test git log %%bash cd test echo "And now some more text..." >> file1.txt %%bash cd test git diff %%bash cd test git commit -a -m"I have made great progress on this critical matter." %%bash cd test git log %%bash cd test git log --oneline --topo-order --graph %%bash cd test # We create our alias (this saves it in git's permanent configuration file): git config --global alias.slog "log --oneline --topo-order --graph" # And now we can use it git slog %%bash cd test git mv file1.txt file-newname.txt git status %%bash cd test git commit -a -m"I like this new name better" echo "Let's look at the log again:" git slog %%bash cd test git status ls %%bash cd test git branch experiment git checkout experiment %%bash cd test echo "Some crazy idea" > experiment.txt git add experiment.txt git commit -a -m"Trying something new" git slog %%bash cd test git checkout master git slog %%bash cd test echo "All the while, more work goes on in master..." >> file-newname.txt git commit -a -m"The mainline keeps moving" git slog %%bash cd test ls %%bash cd test git merge experiment git slog %%bash cd test ls echo "Let's see if we have any remote repositories here:" git remote -v %%bash cd test git remote add origin https://github.com/fperez/test.git git push -u origin master %%bash cd test git remote -v %%bash # Here I clone my 'test' repo but with a different name, test2, to simulate a 2nd computer git clone https://github.com/fperez/test.git test2 cd test2 pwd git remote -v %%bash cd test2 # working on computer #2 echo "More new content on my experiment" >> experiment.txt git commit -a -m"More work, on machine #2" %%bash cd test2 git push %%bash cd test git pull %%bash cd test git branch trouble git checkout trouble echo "This is going to be a problem..." >> experiment.txt git commit -a -m"Changes in the trouble branch" %%bash cd test git checkout master echo "More work on the master branch..." >> experiment.txt git commit -a -m"Mainline work" %%bash cd test git merge trouble %%bash cd test cat experiment.txt %%bash cd test cat experiment.txt %%bash cd test git commit -a -m"Completed merge of trouble, fixing conflicts along the way" git slog from IPython.display import YouTubeVideo YouTubeVideo('U8GBXvdmHT4')