Peter Ogden and Josh Levine. Motivation High level overview Walk through the common operations ...

Post on 29-Dec-2015

215 views 0 download

Transcript of Peter Ogden and Josh Levine. Motivation High level overview Walk through the common operations ...

Git: Introduction and Tutorial

Peter Ogden and Josh Levine

Motivation High level overview Walk through the common operations How not to break things (too badly)

What to expect

Detailed usage Command reference Internal functionality Advanced topics

What not to expect

Do you…◦ Use more than one computer?◦ Collaborate?◦ Break stuff in unknown ways?◦ Backup?

Why source control?

Widely used in the open source community◦ Linux, KDE, LLVM, Github

Supported natively in CAS Available for every platform Wide variety of tools and interfaces Offline working

Why Git?

What is Git?

Visible files◦ Current state of the folder

Hidden history◦ Collection of commits◦ Reference to the current commit

What is a Git repository?

Contains a diff Has metadata

◦ Message◦ Time◦ Author

Linked to previous commit Commit ID is the hash of everything

What is a commit?

All communication is explicit Push to put things in a remote repository Pull to bring things from a remote repository

How do repositories communicate?

DEMONSTRATION 1Setting up a new repository

Terminology◦ Tracked – files known to git◦ Index – files to be committed◦ Staged – changes in the index

Committing Work

addingUntrackedUnstaged committingIn index Committed

DEMONSTRATION 2Committing and pushing

Two stages in pulling◦ Fetch all commits from the remote server◦ Update the local version with remote changes

Conflicts◦ Someone else may have changed the file◦ Git will try to apply all changes◦ May require help

Pulling and merging

Pushing

Pushing

The push will fail - “non fast-forward”

Pushing

DEMONSTRATION 3Collaborative working

Only add files you mean to◦ thumbs.db◦ .trash◦ vim temporary files

Failing to pull before a push Make sure everything is committed before

pulling

Common Pitfalls

Questions

Set name and email◦ git config --global user.email pko11@ic.ac.uk

◦ git config --global user.name “Peter Ogden”

Initialise an empty repository◦ git init

Committing work

Getting started

Create remote repository - e.g. on ee-casgit Add remote server

◦ git remote add origin git@ee-casgit:pko11_test Push to server

◦ git push origin HEAD

Pushing to a remote server

Remote to push to

Commit to push

What is the current state of the repository?◦ git status

What has changed since last commit?◦ git diff

What is currently in the index?◦ git diff --cached

What was the last commit?◦ git show

What are all the commits before the current?◦ git log

Graphical view of history◦ gitk

Other useful commands