CoEPP RC
 

Git Software Guide

Learning git

Configuring git on your workstation (client)

Before you start using git you should write your own configuration file called ~/.gitconfig. The sample below sets your git user details and enables the very useful color options for various outputs.

[user]
  name   = Joe Blow
  email  = jblow@unimelb.edu.au
[color]
  diff   = auto
  status = auto
  branch = auto
[core]
  excludesfile = ~/.gitignore

Git ignore file should contain the following if you are a vim user:

*.swp

Useful terms to know

index      : also known as the staging area - where files go when adding them and before committing them.

Branch names -

master     : default development branch
origin     : default upstream repo branch
HEAD       : pointer to current branch last commit
FETCH_HEAD : most recent fetched upstream HEAD

SHOW

git status

Display paths that have differences between

  • index file and current HEAD
  • working tree and index file (unless gitignore ignores the files)
git diff

Displays diffs between tracked files in the working tree and the index (be aware this doesn't show added files in the working tree - use git status to show these. It does show deleted files though since they are tracked)

git diff --cached [commit]

Displays diffs between index file and the last commit (default HEAD)

git diff [commit]

Displays diffs between working tree and the commit specified (ie HEAD)

git reset --hard

Reset the state of the index file and the working tree back to the last commit (except for files added in the working tree that aren't tracked)

Examples

Manually create a local repository from an existing remote repository (same as git clone /afs/athena/repo/systems/project.git)

cd workdir
mkdir project ; cd project
git init
git remote add origin /afs/athena/repo/systems/project.git
git fetch
git checkout -b master FETCH_HEAD

Manually update local repository with latest version from remote repository (same as git pull)

cd workdir/project
git remote                           # should display output ie. origin
git config --get remote.origin.url   # should display location of upstream repo
git fetch
git merge origin master
Generate an upstream repository:
andres@alap2:/tmp$ mkdir /tmp/remote
andres@alap2:/tmp$ cd /tmp/remote/
andres@alap2:/tmp/remote$ git init –bare
Initialized empty Git repository in /tmp/remote/
andres@alap2:/tmp/remote$ cd ../

Local clone:
andres@alap2:/tmp$ git clone /tmp/remote local
Initialized empty Git repository in /tmp/local/.git/
warning: You appear to have cloned an empty repository.
andres@alap2:/tmp$ cd local/
andres@alap2:/tmp/local$ ls
andres@alap2:/tmp/local$ git
andres@alap2:/tmp/local$ echo “first commit” > foo
andres@alap2:/tmp/local$ git add foo
andres@alap2:/tmp/local$ git commit -m “Hey”
[master (root-commit) ca4ee85] Hey
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 foo

Publish to your private upstream repository:
andres@alap2:/tmp/local$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 216 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /tmp/remote
* [new branch] master -> master
andres@alap2:/tmp/local$ git fetch
andres@alap2:/tmp/local$ git branch
* master
andres@alap2:/tmp/local$ git branch -r
origin/master
andres@alap2:/tmp/local$

Do a second clone “on another machine”:
andres@alap2:/tmp/local$ cd /tmp/
andres@alap2:/tmp$ git clone /tmp/remote local2
Initialized empty Git repository in /tmp/local2/.git/
andres@alap2:/tmp$ cd local2/
andres@alap2:/tmp/local2$ ls
foo
andres@alap2:/tmp/local2$ echo “yet another foo sighted” >> foo
andres@alap2:/tmp/local2$ git add foo
andres@alap2:/tmp/local2$ git commit -m “bar”
[master 3ddd750] bar
1 files changed, 1 insertions(+), 0 deletions(-)
andres@alap2:/tmp/local2$ git push
Counting objects: 5, done.
Writing objects: 100% (3/3), 268 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /tmp/remote
ca4ee85..3ddd750 master -> master
Ok, we published our own changes…

Lets see if we can incorporate them on the other clone:
andres@alap2:/tmp/local2$ cd /tmp/local
andres@alap2:/tmp/local$ git fetch
Unpacking objects: 100% (3/3), done.
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
From /tmp/remote
ca4ee85..3ddd750 master -> origin/master
andres@alap2:/tmp/local$ cat foo
first commit
andres@alap2:/tmp/local$ git merge origin/master
Updating ca4ee85..3ddd750
Fast forward
foo | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
andres@alap2:/tmp/local$ cat foo
first commit
yet another foo sighted

General Information

Repository Index (staging) workdir
Edit files
← add, remove, rename
Committing
← commit
Reading Tree
checkout, read-tree, reset →
Checking out
checkout, checkout-index, reset →
git.txt · Last modified: 2013/07/03 17:07 by scrosby
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki