Slide 1

Slide 1 text

Git 101 @jenssegers

Slide 2

Slide 2 text

What is Git Code Repository Versioning Team & control

Slide 3

Slide 3 text

Installing Git • Windows Git Bash with MinGW • OSX and Linux Terminal git-scm.com

Slide 4

Slide 4 text

Git configuration $ git config --global user.name “Your Name” $ git config --global user.email “[email protected]

Slide 5

Slide 5 text

Basics

Slide 6

Slide 6 text

Creating a local repository $ git init Initialized empty Git repository in Hello/.git/ $ git remote add origin [email protected]:user/ Hello.git

Slide 7

Slide 7 text

A new github repository [email protected]:user/Hello.git

Slide 8

Slide 8 text

Checkout an existing repository $ git clone [email protected]:oSoc13/Media.git Cloning into 'Media'... Resolving deltas: 100% (2/2), done.

Slide 9

Slide 9 text

git add Add changes to the index $ git add README $ git add subfolder/* Add all files (including deleted files) $ git add -A

Slide 10

Slide 10 text

git commit Create a new version of repository with added changes $ git commit -m “Adding readme” [master] created d9e1758: “Adding readme” 1 files changed, 1 insertions(+), 0 deletions(-)

Slide 11

Slide 11 text

git push Push commits 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)

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Conflicts

Slide 14

Slide 14 text

Conflicts A file was modified since the last pull $ git push origin master ! [rejected] master -> master (non-fast- forward)

Slide 15

Slide 15 text

Inspecting the conflict Update your repository $ git pull View conflict info $ git status Unmerged paths: both modified: README

Slide 16

Slide 16 text

Resolving the conflict Open the conflicted file in your favorite editor $ nano README <<<<<<< HEAD $var = ‘foo’; ======= $var = ‘bar’; >>>>>>> a0b0bf3 ] ] local repository remote repository

Slide 17

Slide 17 text

Push merged file $ git add README $ git commit -m “Merging” $ git push origin master

Slide 18

Slide 18 text

Branching

Slide 19

Slide 19 text

Branches

Slide 20

Slide 20 text

Typical branches • Master The latest stable version of the project • Staging/Develop The branch where the a beta version is tested before it is merged into the master branch • Feature X A branch where a specific feature is being developed

Slide 21

Slide 21 text

Creating a branch From the base branch $ git branch feature-x Switching to the new branch $ git checkout feature-x

Slide 22

Slide 22 text

Merging a branch Switch to the base branch you want to merge in $ git checkout master Merge with the branch $ git merge staging

Slide 23

Slide 23 text

Updating a branch Update a feature branch with master branch bug fixes $ git checkout feature-x $ git merge master

Slide 24

Slide 24 text

Tips and tricks

Slide 25

Slide 25 text

.gitignore A list of files that should be ignored # OS generated files .DS_Store .Trashes Thumbs.db # Config Config.php

Slide 26

Slide 26 text

When all hope is lost Revert all changes to the last pulled version $ git reset --hard HEAD

Slide 27

Slide 27 text

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]

Slide 28

Slide 28 text

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.

Slide 29

Slide 29 text

Get git’n

Slide 30

Slide 30 text

Learn git in 15 minutes try.github.io

Slide 31

Slide 31 text

Git guide rogerdudler.github.io /git-guide

Slide 32

Slide 32 text

Git cheat sheet rogerdudler.github.io /git-guide/files/ git_cheat_sheet.pdf

Slide 33

Slide 33 text

Git branches pcottle.github.io/ learnGitBranching/

Slide 34

Slide 34 text

Good luck