Download the Git commandline client at https://git-scm.com/downloads.

Learning Git

http://git.rocks

https://try.github.io

http://learngitbranching.js.org/

Load the Git module

On Bluehive, first load the "git" module.

$ module load git
$ module list
Currently Loaded Modulefiles:
1) slurm/15.08.7 2) circ 3) git/2.8.3

Configure Git

It is important to configure your Git username and email address as every Git commit will use this information to identify you as the author.

On your shell, type the following command to add your username and email address:

$ git config --global user.name "YOUR NAME"
$ git config --global user.email your_email_address@example.com

You'll need to do this once on Bluehive and any personal computers you will be using Git on.

Basic Git commands

Set up a repository

Initialize a new repository in the current directory

$ git init .
Initialized empty Git repository in /home/rlemley/tmp/myproject/.git/

Clone an existing repository GitLab projects will display the URL to clone on the project page. Clone URL

$ git clone git@gitlab.circ.rochester.edu:rlemley/hello-world.git
Initialized empty Git repository in /gpfs/fs1/home/rlemley/git/hello-world/.git/
remote: Counting objects: 175, done.
remote: Compressing objects: 100% (102/102), done.
remote: Total 175 (delta 51), reused 157 (delta 46)
Receiving objects: 100% (175/175), 19.62 KiB, done.
Resolving deltas: 100% (51/51), done.

Repository Status

Get status of a repository

$ git status
# On branch master
nothing to commit (working directory clean)

View the changes you've made

$ git status
# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#      python3.py
nothing added to commit but untracked files present (use "git add" to track)

Commiting changes

Stage the changes for commit

$ git add python3.py

Commit the changes "git commit" will commit any staged changes to the local repository. An editor will open (normally vi) for you to enter a changelog.

$ git commit

Or, use the -m option to "git commit" to give a changelog entry on the commandline.

$ git commit -m "Add python3 example"
[master] Add python v3 example
1 files changed, 2 insertions(+), 0 deletions(-)
create mode 100644 python3.py

ChangeLog

View the changelog

$ git log
commit f8943e3b9f9c4119b5cde646231b0ca5bea2b626
Merge: f9cf5de 3e5a0e4
Author: Sarah Bird 
Date: Mon Sep 12 10:42:04 2016 -0400
    Merge branch 'master' into local-hacker-slides
commit 3e5a0e4d32f8bda01578c14771cf1aabefee63fd
Author: Jack Singleton 
Date: Sun Apr 24 23:22:11 2016 -0700
    bump version

Remote repositories

When you clone a repository, Git automatically configures it as a remote repository. Add a remote repository You can add a remote repository through the commandline.

$ git remote add NAME REMOTE-URL
$ git remote add github 

Pull changes from remote

$ git pull
Already up-to-date.

Push changes to remote

$ git push

Git branches

View list of branches
The asterisk indicates the current branch.

$ git branch
* alternative-python
  master

Create a branch

$ git checkout -b NAME-OF-BRANCH
$ git checkout -b alternative-python
Switched to a new branch 'alternative-python'

Work on an existing branch

$ git checkout NAME-OF-BRANCH
$ git checkout alternative-python
Switched to branch 'alternative-python'

Push to a remote branch

$ git push REMOTE NAME-OF-BRANCH
$ git push origin alternative-python
Counting objects: 5, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 362 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@gitlab.circ.rochester.edu:rlemley/hello-world.git
 * [new branch]      alternative-python -> alternative-python

Git will automatically set up your local branch to track the remote branch.

Merge branches
Merging incorporates changes from another branch into the current one.

$ git merge alternative-python
Merge made by the 'recursive' strategy.
README.md | 6 ++++++
python.py | 4 +++-
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 README.md