/gitnotes-1

Notes from the Research Computing Workshop on using Git

Configuration

Global configuration stored under ~/.gitconfig. Local configuration stored under .git/config. Can edit with a text editor.

git config --global user.name "Tyson Whitehead" 
git config --global user.email "twhitehead@gmail.com" 
git config --global color.ui auto 
git config --global core.editor nano

Initialization

Creates the .git directory. To undo rm -r .git.

mkdir $folder
cd $folder
git init

Initialization

Creates the .git directory. To undo rm -r .git.

mkdir $folder
cd $folder
git init

Creating the next version

First view the status to see where things are at

git status

Add the changes you want in the next version (the -p option asks you change by change and is not required to just add everything)

git add -p $file

If you want to remove a file

git rm $file

Save the next version

To save the next version run

git commit

For a log message, describe why you made the change, not what change you made as the computer can tell you the latter but not the former. Make the first line a brief oneline overview.

Viewing changes

You can view all the log messages going back to the start with (the --graph options draws a pretty graph and --oneline just displays the first line of each message)

git log

You can view the changes that aren't staged yet with (you can specify a file to just see the changes in that file)

git diff

You can view how the next version (the staged version) differs from the previous version with

git diff --staged

View changes between Folder/Working tree and master

git diff master

View changes between two commits (see following section for overview on specifying commits)

git diff 3b12245 def106f

Specifying commits

Commits can be specified by

  • number: def106f
  • branch name: master
  • going back n steps: master~$n (replace $n with the number)
  • taking the nth branch: master^$n (replace $n with the number)

Branching

Create branch named history, then switch branch and verify (will display a * beside the current branch)

git branch 

Create a new branch called history

git branch history

Switch to a different branch (may overwrite files)

git checkout history

Getting a personal account on SharcNet!

https://www.sharcnet.ca/help/index.php/Getting_an_Account_with_SHARCNET https://ccdb.computecanada.ca