39
Git 101 @jenssegers

Git101

Embed Size (px)

DESCRIPTION

Git101 presntation for iRail Summer of code

Citation preview

Page 1: Git101

Git 101@jenssegers

Page 2: Git101

In a world without Git

Page 3: Git101

Distributed version control

• Speed

• Simple

• Non-linear development

• Fully distributed

• Large projects

Page 4: Git101

Snapshots, no ∆

Page 5: Git101

Distributed

Pieter

Hannes

Jens

Miet

Page 6: Git101

Distributed and managed

Pieter

Hannes

Jens

Miet

Page 7: Git101

Github

Pieter

Hannes

Jens

Page 8: Git101

What is Github?

• Repository hosting service

• Visualization of changes

• Issue tracker

Page 9: Git101

Installing Git

• WindowsGit Bash with MinGW

• OSX and LinuxTerminal

git-scm.com

Page 10: Git101

Git configuration

$ git config --global user.name “Your Name”

$ git config --global user.email “[email protected]

Page 12: Git101

Creating a local repository

$ mkdir Hello

$ cd Hello

$ git init

Initialized empty Git repository in Hello/.git/

$ git remote add origin [email protected]:user/Hello.git

Page 13: Git101

Git Basics

Page 14: Git101

git add

Track files for the next snapshot

$ git add README

$ git add subfolder/

Add all files (including deleted files)

$ git add -A

Page 15: Git101

git rm

Opposite of add, untracks file

$ git rm README

Recursive

$ git rm -r subfolder/

Page 16: Git101

git commit

Create a snapshot of all the added files

$ git commit -m “Adding readme”

[master] created d9e1758: “Adding readme”1 files changed, 1 insertions(+), 0 deletions(-)

Always add an appropriate commit message!

Page 17: Git101

git commit (2)

Automatically detect changed and deleted files

$ git commit -am “Adding readme”

Update a previous commit

$ git commit -am “GUI refactoring”

$ git add new_file

$ git commit --amend

Page 18: Git101

git push

Push commit snapshots to a remote repository

$ git push [remote] [branch]

$ git push origin master

Writing objects: 100% (3/3), 225 bytes, done.Total 3 (delta 0), reused 0 (delta 0)

Page 19: Git101

git pull

Pull updates from a remote repository

$ git pull [remote] [branch]

$ git pull origin master

remote: Total 3 (delta 0), reused 0 (delta 0)Updating d9e1758..c3e12cc

Page 20: Git101

git clone

Work on an existing repository

$ git clone [origin]

$ git clone https://github.com/user/repository.git

Cloning into ...Unpacking objects: 100%, done.

Page 21: Git101

Conflicts

Page 22: Git101

Conflicts

A file was modified since the last pull

$ git push origin master

! [rejected] master -> master (non-fast-forward)

Page 23: Git101

Inspecting the conflict

Update your repository

$ git pull

View conflict info

$ git status

Unmerged paths:both modified: README

Page 24: Git101

Resolving the conflict

Open the conflicted file in your favorite editor

$ nano README

<<<<<<< HEADYes, this is Dog?=======Who is Dog?>>>>>>> a0b0bf3

]]

local repository

remote repository

Page 25: Git101

Push merged file

$ git add README

$ git commit -m “Merging”

$ git push origin master

Page 26: Git101

Branching

Page 27: Git101

Branches

Page 28: Git101

Typical branches

• MasterThe latest stable version of the project

• StagingThe branch where the a beta version is tested before it is merged into the master branch

• Feature XA branch where a specific feature is being developed

Page 29: Git101

Creating a branch

From the base branch

$ git branch feature-x

Switching to the new branch

$ git checkout feature-x

Page 30: Git101

Merging a branch

Switch to the base branch you want to merge in

$ git checkout master

Merge with the branch

$ git merge staging

Page 31: Git101

Updating a branch

Update a feature branch with master branch bug fixes

$ git checkout feature-x

$ git merge master

Page 32: Git101

Removing a branch

$ git branch -D feature-useless

Page 33: Git101

Tips and tricks

Page 34: Git101

.gitignore

A list of files that should be ignored

# OS generated files.DS_Store.TrashesThumbs.db

# ConfigConfig.php

Page 35: Git101

When all hope is lost

Revert all changes to the last pulled version

$ git reset --hard HEAD

Page 36: Git101

Credential cache

Add cache to credentials to prevent typing username and password over and over again

$ git config --global credential.helper cache

Default cache is 15 minutes, to change cache use

$ git config credential.helper 'cache --timeout=3600'

Page 37: Git101

SSH keys

WARNING! Only when you do not have an existing key pair

$ ssh-keygen -t rsa -C "[email protected]"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

Enter passphrase (empty for no passphrase): [Type a passphrase]

Page 38: Git101

SSH keys (2)

Add your public SSH key to your github account (account settings)

$ cat ~/.ssh/id_rsa.pub

Test your settings

$ ssh -T [email protected]

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Page 39: Git101

Good luck

thanksTim De Pauw, Pieter Colpaert, Hannes Van De Vreken