SlideShare a Scribd company logo
1 of 75
GIT

GET READY TO USE IT

DANIEL KUMMER
SENIOR SOFTWARE ENGINEER
NAMICS AG ZÜRICH
WWW.NAMICS.COM
1

FORGET WHAT
YOU KNOW
ABOUT CVS/SVN

GIT IS DIFFERENT
EMPTY YOUR MIND – A FULL ONE
CAN’T LEARN ANYTHING…
THE
BASICS
(NEARLY) EVERY OPERATION IS LOCAL
YOU HAVE YOUR OWN REPO
GIT STORES SNAPSHOTS, NOT DIFFERENCES
GIT ONLY ADDS DATA
STANs REPO
YOUR REPO

ORIGIN

CENTRAL
REPO

IRONs REPO

DISTRIBUTED VCS
ORIGIN

LOCAL
STASH

WORKSPACE

INDEX / STAGE

REPOSITORY

REPOSITORY

CLONE
STATUS
STASH SAVE
STASH POP
STASH APPLY

ADD

COMMIT

COMMIT -A
MERGE
REVERT
CHECKOUT

PUSH
PULL
FETCH
ENVIRONMENT
SETUP
INSTALL GIT
www.git-scm.com

INSTALL SOURCETREE GUI - OR A GUI OF YOUR CHOICE
www.sourcetreeapp.com
INITIAL CONFIG

YOUR IDENITY – COMMIT AUTHOR INFORMATION

$ git config --global user.name “Darth Vader”
$ git config --global user.email darth@deathstar.emp

ADDITIONAL USEFUL GLOBAL SETTINGS
$ git config --global core.filemode false
$ git config --global core.autocrlf true
$ git config --global core.ignorecase false
$ git config --global rerere.enabled true
$ git config --global color.ui true
$ git config --global format.pretty oneline
JOIN A PROJECT

git.namics.com
TELL YOUR MASTER TO ADD YOU TO THE PROJECT
IN 3 STEPS
GENERATE SSH KEYS
$ ssh-keygen –t rsa –C darth.vader@deathstar.emp

UPLOAD YOUR SSH PUBLIC KEY TO YOUR ACCOUNT
https://git.namics.com/keys

CLONE THE REPOSITORY
$ git clone git@git.namics.com:deathstar-v3.git
YOUR CLONE

IS A WORKING COPY OF
THE ORIGINS’ MASTER BRANCH – NONE OTHER!

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

CONTAINS EVERY VERSION OF EVERY FILE
CONTAINS A .GIT FOLDER IN THE ROOT DIRECTORY
WITH EVERYTHING GIT NEEDS
LET’S GET
STARTED!

1.

RECORDING
CHANGES
ORIGIN

LOCAL
STASH

WORKSPACE

INDEX / STAGE

REPOSITORY

REPOSITORY

CLONE
STATUS
STASH SAVE
STASH POP
STASH APPLY

ADD

COMMIT

COMMIT -A
MERGE
REVERT
CHECKOUT

PUSH
PULL
FETCH
FILE STATUS
LIFECYCLE
REMOVE

UNMODIFIED

STAGE

UNTRACKED

ADD

MODIFIED

STAGED
CHECK THE WORKING COPY STATUS
$ git status
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working
directory)
#
# modified: README
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# exhaust_port_plans
LETS ADD A FILE TO THE STAGE – READY FOR COMMIT
$ git add exhaust_port_plans
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: exhaust_port_plans
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working
directory)
#
# modified: README
MORE INFO THAN STATUS WITH DIFF
$ git diff
diff --git a/README b/README
index e69de29..18ef097 100644
--- a/README
+++ b/README
@@ -0,0 +1 @@
+hello my empire minions - let's build a death star that works
this time!
NOW, COMMIT EVERYTHING ADDED TO THE STAGE
$ git commit -m 'add exhaust port plans’
[master e8c1e22] add exhaust port plans
1 file changed, 1 insertion(+)
create mode 100644 exhaust_port_plans

SKIP THE STAGE AREA IF YOU DON’T NEED IT
$ git commit -a -m 'add hello message to readme’
[master 73ceaf6] add hello message to readme
1 file changed, 1 insertion(+)

REMOVE/MOVE FILES WITH

$ git rm

$ git mv
IGNORE THINGS
YOU CAN’T IGNORE ALREADY TRACKED FILES
AN EXAMPLE OF THE .GITIGNORE TEXTFILE
# a comment - this is ignored
*.log
.DS_store
.idea/**/*
**.classpath
**.project
**.settings

(INSIDE THE PROJECTS ROOT DIRECTORY)
RECAP

RECORDING CHANGES

CHECK CURRENT WORKING COPY STATUS

$ git status

ADDING FILES TO THE INDEX
$ git add <pathspec>

SHOW CHANGES
$ git diff

COMMIT TO REPOSITORY
$ git commit [-a] [-m]

(WORKING COPY

INDEX)
MESSED
UP?

2.

UNDOING
THINGS
CHANGE YOUR LAST COMMIT –EX: ADD FORGOTTEN FILES
$ git commit --amend

NEVER AMEND AFTER YOU PUSHED YOUR CHANGES!
UNSTAGE ADDED FILES
$ git status
# Changes to be committed:
#
# new file: alimony_for_luke
$ git reset HEAD alimony_for_luke
$ git reset HEAD alimony_for_luke
# Untracked files:
#
# alimony_for_luke
REVERT CHANGES IN YOUR WORKING DIRECTORY
$ git status
# Changes not staged for commit:
#
# modified: README
#
$ git checkout –- README
$ git status
# On branch master
#
nothing to commit, working directory clean
REVERSE COMMIT
$ git revert <commit>

CREATES NEW COMMITS RECORDING THE REVERT CHANGES
IF YOU GET MERGE CONFLICTS, RESOLVE AND CONTINUE
$ git revert --continue

CANCEL REVERT OPERATION
$ git revert --abort
RECAP

UNDOING THINGS

ALTER LAST COMMIT

$ git commit --amend

UNSTAGE FILES
$ git reset HEAD <file>

REVERT CHANGES
$ git checkout -- <file>

REVERSE COMMIT
$ git revert <commit>
JOIN THE
TEAM EFFORT

3.

WORK WITH
REMOTES
ORIGIN

LOCAL
STASH

WORKSPACE

INDEX / STAGE

REPOSITORY

REPOSITORY

CLONE
STATUS
STASH SAVE
STASH POP
STASH APPLY

ADD

COMMIT

COMMIT -A
MERGE
REVERT
CHECKOUT

PUSH
PULL
FETCH
YOUR CLONED REPO ALREADY HAS A REMOTE - ORIGIN
$ git remote -v
origin git@git.namics.com:deathstar-v3.git (fetch)
origin git@git.namics.com:deathstar-v3.git (push)

ADDING A REMOTE TO YOUR LOCAL REPOSITORY
$ git remote add origin git@git.namics.com:deathstar-v3.git

YOU COULD HAVE MULTIPLE REMOTES
GETTING INFORMATION ABOUT A REMOTE
$ git remote show origin
* remote origin
Fetch URL: git@git.namics.com:deathstar-v3.git
Push URL: git@git.namics.com:deathstar-v3.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
FETCH VS PULL
GET DATA FROM THE REMOTE REPOSITORY

$ git fetch <remote-name>

FETCH ONLY
MANUAL MERGING
FETCH

$ git pull

FETCH AND MERGE
TRACKED BRANCHES
PULL
PUSH CHANGES
PUSH BRANCH TO REMOTE

$ git push <remote-name> <branch-name>

ONLY WORKS IF NOBODY HAS PUSHED IN THE MEANTIME
$ git push origin master
Counting objects: 8, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 650 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To git@git.namics.com:deathstar-v3.git
5d31566..73ceaf6 master -> master
EXPLICITLY PUSH BRANCHES YOU WANT
TO SHARE
PUSH IS REJECTED IF CURRENT BRACH IS BEHIND
$ git push origin master
To git@git.namics.com:deathstar-v3.git
! [rejected]
master -> master (non-fast-forward)
error: failed to push some refs to
'git@git.namics.com:deathstar-v3.git'
hint: Updates were rejected because the tip of your
current branch is behind
hint: its remote counterpart. Integrate the remote
changes (e.g.
hint: 'git pull ...') before pushing again.
RECAP

REMOTES

LIST REMOTES
$ git remove -v

ADDING REMOTES
$ git remote add <shortname> <url>

INFORMATION ABOUT REMOTE
$ git remote show <shortname>
RECAP

REMOTES

FETCH FROM REMOTES
$ git fetch <remote-name>

PULL FROM REMOTES
$ git pull

PUSH CHANGES TO REMOTES
$ git push <remote-name> <branch-name>
LEAVE YOUR
MARK

4. TAGGING
LIGHTWEIGHT VS ANNOTATED
$ git tag v0.1

$ git tag –a v1.0 –m ‘first rel’

CHECKSUM IN A FILE

FULL OBJECT

INTERNAL
PROJECTS

CHECKSUM
AUTHOR INFO
GPG SIGNED (-s)
OPEN SOURCE
REPOSITORIES
TAGS MUST BE PUSHED SEPARATELY
$ git push origin --tags
Total 0 (delta 0), reused 0 (delta 0)
To git@git.namics.com:deathstar-v3.git
* [new tag]
1.0 -> 1.0

LIST TAGS WITH
$ git tag
1.0
1.1
BREAK
TIME
BACK IN

15
THE KILLER
FEATURE

5.BRANCHING
COMMITS AND
BRANCHES

COMMIT - OBJECT THAT CONTAINS A POINTER
TO THE SNAPSHOT OF THE CONTENT
THE GIT HISTORY IS A LINKED LIST OF POINTERS
98ca9

34ac2

f30ab

Snapshot A

Snapshot B

Snapshot C
A BRANCH IS A LIGHTWEIGHT POINTER TO A COMMIT
LOCAL POINTER TO YOUR CURRENT BRANCH
MASTER BRANCH POINTER
98ca9

34ac2

TESTING BRANCH POINTER

HEAD

master

f30ab

testing
CREATING A BRANCH IS WRITING
41 BYTES TO A FILE
(SHA-1 HASH PLUS NEWLINE)

THAT’S WHY
BRANCHING IS
SUPER FAST
CREATE A NEW BRANCH
$ git branch testing

CHECKOUT EXISTING BRANCH
$ git checkout testing

SWITCHING TAKES A BLINK OF THE EYE
EVERYTHING HAPPENS IN
YOUR WORKING COPY

98ca9

34ac2

NOW YOU’RE ON THE TESTING BRANCH
SHORT FORM FOR BRANCH AND CHECKOUT
$ git checkout –b testing

master

f30ab

testing

HEAD
BASIC
MERGING
C0

I WANT TO MERGE
ISS53 INTO MASTER
Snapshot to
Merge Into
Common
Ancestor

C1

CHECKOUT THE TARGET BRANCH

C2

master

C4

C3

C5

$ git checkout master

MERGE THE ISSUE BRANCH
$ git merge iss53

iss53

Snapshot to
Merge In
master

MERGE MAGIC HAPPENED:
C0

C1

C2

THE RESULT
$ git checkout master
$ git merge iss53

C4

C3

C6

C5

iss53

Auto-merging README
Merge made by the 'recursive' strategy.
README | 1 +
1 file changed, 1 insertion(+)

FEATURE BRANCH NO LONGER NEEDED, DELETE IT
$ git branch –d iss53
RESOLVING
CONFLICTS
WHAT IF MAGIC DOESN’T HAPPEN?

CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the
result.

USE A MERGETOOL TO RESOLVE THE CONFLICTS
$ git mergetool

(DIFFMERGE FOR EXAMPLE)
COMMIT CHANGES AFTER RESOLVING THE CONFLICTS
$ git commit
Merge branch 'testing'
Conflicts:
README
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
#
.git/MERGE_HEAD
# and try again.

THE MESSAGE IS AUTOGENERATED
YOU CAN STILL EDIT IT OF COURSE
RECAP

MERGING

CREATE BRANCH

$ git branch <branchname>

CHECKOUT BRANCH
$ git checkout <branchname>

MERGE BRANCHES
$ git merge <commit>

RESOLVE CONFLICTS
$ git mergetool
BRANCH
MANAGEMENT
LIST BRANCHES

-a: remote branches

$ git branch [--merged] [-a]

DELETE BRANCHES
$ git branch [-d] [-D]

-D: force delete unmerged
REMOTE BRANCH
PUSHING TO REMOTE BRANCHES
$ git push [remote] [branch]

TRACKING REMOTE BRANCHES
$ git checkout –b <branch> <remotename>/<branch>

ALLOWS GIT PULL INSTEAD OF GIT FETCH
DELETING REMOTE BRANCHES (NOTE THE : )
$ git push <remotename> :<branch>
RECAP

BRANCH MANAGEMENT

LIST ALL BRANCHES

$ git branch -a

TRACKING REMOTE BRANCHES
$ git checkout –b <branch> <remotename>/<branch>

PUSHING TO REMOTE BRANCHES
$ git push [remote] [branch]

DELETING REMOTE BRANCHES (NOTE THE : )
$ git push <remotename> :<branch>
BRANCHING
WORKFLOWS
GIT FLOW

STRUCTURE FOR LARGE PROJECTS

FEATURE BRANCH NEW BRANCH FOR EVERY FEATURE
CENTRALIZED

SVN LIKE

FORKING

USED BY GITLAB
GIT FLOW
MASTER

OFFICIAL RELEASE HISTORY

HOTFIX

PRODUCTION RELASE PATCHING
RELEASE POLISHING – NO NEW FEATURES

DEVELOP

FEATURE INTEGRATION

FEATURE

FEATURE DEVELOPMENT, CHILD OF DEVELOP
GIT FLOW
REBASE
A MERGING
ALTERNATIVE
TAKE ALL COMMITED CHANGES ON ONE BRANCH
AND REPLAY THEM ON ANOTHER ONE
SAME RESULT AS MERGE BUT CLEANER HISTORY
IT APPEARS THAT ALL WORK HAPPENED IN SERIES
B

E

F

master

C

BEFORE

A

D

experiment

master

AFTER

A

B

E

F

C'

D'
experiment
DO NOT REBASE PUSHED COMMITS
REBASING ABANDONS EXISTING COMMITS
AND CREATES SIMILAR NEW ONES
USE REBASE IF YOU KNOW WHAT YOU’RE DOING
NEWBIES SHOULD USE MERGE – IT’S SIMPLER
REBASE A BRANCH ONTOP OF THE CURRENT ONE
$ git rebase <branch>

REBASE ONTO TARGET BRANCHES
$ git rebase --onto <branches>
MASHUP
COMBINATIONS

6.

REPOSITORY
WITHIN REPO
SUBMODULES

TRACKED BY THE EXACT COMMIT SPECIFIED IN THE
PARENT REPOSITORY – LOCKED TO COMMIT
GOOD FOR NOT TOO FREQUENT UPDATES
THE WHOLE REPOSITORY IS INCLUDED AS SUBMODULE
PARTIAL INCLUDE IS NOT POSSIBLE
MANY BUTS’

LOTS OF
DISADVANTGES
AND PITFALLS

YOU CAN’T JUST CLONE THE PARENT REPOSITORY
SUBMODULE NEEDS TO BE INITIALIZED AND UPDATED
NEVER AUTOMATICALLY UPDATED WHEN THE
SUBMODULE REPOSITORY IS UPDATES
YOU CAN’T BRANCH EASILY
ACCIDENTIAL SUBMODULE REVERT HAPPENS EASILY

LOTS OF THINKING INVOLVED WHEN USING SUBMODULES
SUBTREE MERGE
IT’S A MERGE STRATEGY
(LIKE RECURSIVE FOR BRANCHES)
NO NEW METADATA
SUB-PROJECT CONTRIBUTION IS SLIGHTLY MORE
COMPLICATED
YOU ARE RESPONSIBLE FOR NOT MIXING SUPER
AND SUB-PROJECT CODE
SOME
CAKE

7.

USEFUL
TOOLS
INTERACTIVE
MODE

ENHANCED COMMAND LINE

ADD –i TO COMMAND LINE; FOR EXAMPLE

$ git add –i
staged unstaged path
1: unchanged
+0/-1 TODO
*** Commands ***
1: status 2: update
3: revert 4: add untracked
5: patch
6: diff
7: quit
8: help
What now>
THE STASH
A “DIRTY LITTLE HELPER”
STORE YOUR LOCAL MODIFICATIONS AWAY
AND REVERT WORKING COPY TO HEAD COMMIT
SAVE CHANGES TO STASH
$ git stash

APPLY STASH
$ git stash pop
ORIGIN

LOCAL
STASH

WORKSPACE

INDEX / STAGE

REPOSITORY

REPOSITORY

CLONE
STATUS
STASH SAVE
STASH POP
STASH APPLY

ADD

COMMIT

COMMIT -A
MERGE
REVERT
CHECKOUT

PUSH
PULL
FETCH
CHERRY PICK

APPLY CHANGES FROM ANOTHER COMMIT

$ git cherry-pick <commit>

BEFORE
C0

C1

AFTER

HEAD

C2

C4

C0

C1

HEAD

C2

C4

C6

git cherry pick C3

C3

C5

APPLY CHANGES FROM C3
AS NEW COMMIT ON TOP OF C4

C3

C5
BISECT
YOUR CODE

FIND THE CHANGE WHICH INTRODUCED THE BUG

$ git bisect start

CURRENT VESION (HEAD) IS BAD
$ git bisect bad

LAST TESTED VERSION WHICH WAS GOOD
$ git bisect good v0.4
GIT
SVN

BIDIRECTIONAL OPERATIONS
BETWEEN GIT AND SVN
TRACK STANDARD SVN REPOSITORY
“TRUNK/BRANCHES/TAGS”

UPDATE GIT WITH FETCH
$ git fetch

UPDATE SVN WITH DCOMMIT
$ git dcommit
MOST COMMON
PROBLEMS

8.

AND
SOLUTIONS
I CAN’T CLONE
CHECK YOUR SSH CONNECTION
$ ssh -T git@git.namics.com
Welcome to GitLab, Daniel Kummer!

VERIFY YOUR PUBLIC-KEY IN YOUR GITLAB PROFILE
VERIFY YOUR PROJECT ACCESS IN GITLAB
TRY RE-ADDING YOUR KEY TO SSH-AGENT
$ ssh-add –D
$ ssh-add ~/.ssh/id_rsa

# deletes all identities in agent
# add key to agent
I CAN’T PULL

VERIFY THAT THERE ARE NO UNCOMMITED CHANGES
VERIFY THAT YOUR LOCAL BRANCH TRACKS A
REMOTE ONE (TRACKED ONES ARE BLUE)

$ git branch -vv
* master 4658814 [origin/master]

SUBSEQUENT TRACKING OF REMOTE BRANCHES
$ git branch --set-upstream-to <local-branch> origin/
<remote-branch>
I CAN’T PUSH
CHECK IF YOUR LOCAL BRANCH IS BEHIND
$ git push
# Your branch is behind 'origin/master' by 5 commits

CHECK IF YOUR LOCAL BRANCH IS TRACKING A
REMOTE ONE
I CAN’T DELETE
A FILE FROM REPO
TRY DELETING THE CACHED FILE ONLY
(LEAVES WORKING COPY INTACT)

$ git rm --cached eclipse.properties

IF THE FILE NEEDS TO BE REMOVED FROM THE HISTORY
$ git filter-branch …

https://help.github.com/articles/remove-sensitive-data
MORE MATERIAL
GIT-PRO BOOK / REFERENCE
http://git-scm.com/

TUTORIALS
https://www.atlassian.com/git

GIT FLOW CHEATSHEET
http://danielkummer.github.io/git-flow-cheatsheet

15 MINUTES INTERACTIVE TUTORIAL
http://try.github.io
GETTING HELP
$ git help <command>

ASK YOUR LOCAL GURU
GOOGLE IT
CONT@CT ME
CONGRATULATION
YOU MADE IT !

More Related Content

What's hot

Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Introducing GitLab (September 2018)
Introducing GitLab (September 2018)Introducing GitLab (September 2018)
Introducing GitLab (September 2018)Noa Harel
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewRueful Robin
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeMd Swawibe Ul Alam
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitColin Su
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hubNaveen Pandey
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 

What's hot (20)

Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Introducing GitLab
Introducing GitLabIntroducing GitLab
Introducing GitLab
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Github basics
Github basicsGithub basics
Github basics
 
Introducing GitLab (September 2018)
Introducing GitLab (September 2018)Introducing GitLab (September 2018)
Introducing GitLab (September 2018)
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
 
Git basics
Git basicsGit basics
Git basics
 
Git and github
Git and githubGit and github
Git and github
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Aprendendo Git
Aprendendo GitAprendendo Git
Aprendendo Git
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 

Viewers also liked

DIY IoT - The InfoDome
DIY IoT - The InfoDomeDIY IoT - The InfoDome
DIY IoT - The InfoDomeDaniel Kummer
 
Effective Git with Eclipse
Effective Git with EclipseEffective Git with Eclipse
Effective Git with EclipseChris Aniszczyk
 
Git for beginner
Git for beginnerGit for beginner
Git for beginnerTrung Huynh
 
Git like a Pro (How to use it as it was meant to)
Git like a Pro (How to use it as it was meant to)Git like a Pro (How to use it as it was meant to)
Git like a Pro (How to use it as it was meant to)Dennis Doomen
 
'Git started' für Fortgeschrittene!
'Git started' für Fortgeschrittene!'Git started' für Fortgeschrittene!
'Git started' für Fortgeschrittene!Benjamin Schmid
 
はじめようGit
はじめようGitはじめようGit
はじめようGittechscore
 
15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門to_ueda
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンドYUKI Kaoru
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフローadd20
 
はじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーはじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーSaeko Yamamoto
 
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜Takashi Uemura
 
いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0Masakazu Matsushita
 
デザイナのためのGit入門
デザイナのためのGit入門デザイナのためのGit入門
デザイナのためのGit入門dsuke Takaoka
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理Takafumi Yoshida
 
こわくない Git
こわくない Gitこわくない Git
こわくない GitKota Saito
 

Viewers also liked (19)

DIY IoT - The InfoDome
DIY IoT - The InfoDomeDIY IoT - The InfoDome
DIY IoT - The InfoDome
 
Effective Git with Eclipse
Effective Git with EclipseEffective Git with Eclipse
Effective Git with Eclipse
 
Git in action
Git in actionGit in action
Git in action
 
Git
GitGit
Git
 
Git for beginner
Git for beginnerGit for beginner
Git for beginner
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Git like a Pro (How to use it as it was meant to)
Git like a Pro (How to use it as it was meant to)Git like a Pro (How to use it as it was meant to)
Git like a Pro (How to use it as it was meant to)
 
'Git started' für Fortgeschrittene!
'Git started' für Fortgeschrittene!'Git started' für Fortgeschrittene!
'Git started' für Fortgeschrittene!
 
はじめようGit
はじめようGitはじめようGit
はじめようGit
 
15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門
 
Gitのよく使うコマンド
Gitのよく使うコマンドGitのよく使うコマンド
Gitのよく使うコマンド
 
バージョン管理のワークフロー
バージョン管理のワークフローバージョン管理のワークフロー
バージョン管理のワークフロー
 
はじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダーはじめてのGit forデザイナー&コーダー
はじめてのGit forデザイナー&コーダー
 
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
もしWordPressユーザーがGitを使ったら 〜WordPressテーマを共同編集しよう〜
 
いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0
 
デザイナのためのGit入門
デザイナのためのGit入門デザイナのためのGit入門
デザイナのためのGit入門
 
一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理一人でもはじめるGitでバージョン管理
一人でもはじめるGitでバージョン管理
 
こわくない Git
こわくない Gitこわくない Git
こわくない Git
 
いつやるの?Git入門
いつやるの?Git入門いつやるの?Git入門
いつやるの?Git入門
 

Similar to Git - Get Ready To Use It

Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control SystemVictor Wong
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With GitHoffman Lab
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get GitSusan Tan
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHubLucas Videla
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stashFederico Panini
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for ArtistsDavid Newbury
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Codemotion
 
Git introduction
Git introductionGit introduction
Git introductionmxamin
 

Similar to Git - Get Ready To Use It (20)

Gittalk
GittalkGittalk
Gittalk
 
Loading...git
Loading...gitLoading...git
Loading...git
 
Git Distributed Version Control System
Git   Distributed Version Control SystemGit   Distributed Version Control System
Git Distributed Version Control System
 
Git basics
Git basicsGit basics
Git basics
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
 
Git
GitGit
Git
 
Git
GitGit
Git
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stash
 
Git
GitGit
Git
 
Git rebase
Git rebaseGit rebase
Git rebase
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git_real_slides
Git_real_slidesGit_real_slides
Git_real_slides
 
Introduction to Git for Artists
Introduction to Git for ArtistsIntroduction to Git for Artists
Introduction to Git for Artists
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
 
Git introduction
Git introductionGit introduction
Git introduction
 
git session --interactive
git session --interactivegit session --interactive
git session --interactive
 

More from Daniel Kummer

Bluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the BulletsBluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the BulletsDaniel Kummer
 
Changing internet - where we come from where we go
Changing internet - where we come from where we goChanging internet - where we come from where we go
Changing internet - where we come from where we goDaniel Kummer
 
Magnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - StorytellingMagnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - StorytellingDaniel Kummer
 
Code Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practiceCode Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practiceDaniel Kummer
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumberDaniel Kummer
 
Git get-the-job-done
Git get-the-job-doneGit get-the-job-done
Git get-the-job-doneDaniel Kummer
 

More from Daniel Kummer (10)

Git code reviews
Git code reviewsGit code reviews
Git code reviews
 
Bluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the BulletsBluetooth LE - Dodging the Bullets
Bluetooth LE - Dodging the Bullets
 
HTTP
HTTPHTTP
HTTP
 
Changing internet - where we come from where we go
Changing internet - where we come from where we goChanging internet - where we come from where we go
Changing internet - where we come from where we go
 
Magnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - StorytellingMagnolia 4.5 Migration - Storytelling
Magnolia 4.5 Migration - Storytelling
 
Code Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practiceCode Kata Workshop - Improve your skills through deliberate practice
Code Kata Workshop - Improve your skills through deliberate practice
 
Clean Code
Clean CodeClean Code
Clean Code
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Git get-the-job-done
Git get-the-job-doneGit get-the-job-done
Git get-the-job-done
 
Git! Why? How?
Git! Why? How?Git! Why? How?
Git! Why? How?
 

Recently uploaded

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Git - Get Ready To Use It

  • 1. GIT GET READY TO USE IT DANIEL KUMMER SENIOR SOFTWARE ENGINEER NAMICS AG ZÜRICH WWW.NAMICS.COM
  • 2. 1 FORGET WHAT YOU KNOW ABOUT CVS/SVN GIT IS DIFFERENT EMPTY YOUR MIND – A FULL ONE CAN’T LEARN ANYTHING…
  • 3. THE BASICS (NEARLY) EVERY OPERATION IS LOCAL YOU HAVE YOUR OWN REPO GIT STORES SNAPSHOTS, NOT DIFFERENCES GIT ONLY ADDS DATA
  • 5. ORIGIN LOCAL STASH WORKSPACE INDEX / STAGE REPOSITORY REPOSITORY CLONE STATUS STASH SAVE STASH POP STASH APPLY ADD COMMIT COMMIT -A MERGE REVERT CHECKOUT PUSH PULL FETCH
  • 6. ENVIRONMENT SETUP INSTALL GIT www.git-scm.com INSTALL SOURCETREE GUI - OR A GUI OF YOUR CHOICE www.sourcetreeapp.com
  • 7. INITIAL CONFIG YOUR IDENITY – COMMIT AUTHOR INFORMATION $ git config --global user.name “Darth Vader” $ git config --global user.email darth@deathstar.emp ADDITIONAL USEFUL GLOBAL SETTINGS $ git config --global core.filemode false $ git config --global core.autocrlf true $ git config --global core.ignorecase false $ git config --global rerere.enabled true $ git config --global color.ui true $ git config --global format.pretty oneline
  • 8. JOIN A PROJECT git.namics.com TELL YOUR MASTER TO ADD YOU TO THE PROJECT
  • 9. IN 3 STEPS GENERATE SSH KEYS $ ssh-keygen –t rsa –C darth.vader@deathstar.emp UPLOAD YOUR SSH PUBLIC KEY TO YOUR ACCOUNT https://git.namics.com/keys CLONE THE REPOSITORY $ git clone git@git.namics.com:deathstar-v3.git
  • 10. YOUR CLONE IS A WORKING COPY OF THE ORIGINS’ MASTER BRANCH – NONE OTHER! $ git status # On branch master nothing to commit, working directory clean CONTAINS EVERY VERSION OF EVERY FILE CONTAINS A .GIT FOLDER IN THE ROOT DIRECTORY WITH EVERYTHING GIT NEEDS
  • 12. ORIGIN LOCAL STASH WORKSPACE INDEX / STAGE REPOSITORY REPOSITORY CLONE STATUS STASH SAVE STASH POP STASH APPLY ADD COMMIT COMMIT -A MERGE REVERT CHECKOUT PUSH PULL FETCH
  • 14. CHECK THE WORKING COPY STATUS $ git status # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # exhaust_port_plans
  • 15. LETS ADD A FILE TO THE STAGE – READY FOR COMMIT $ git add exhaust_port_plans $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: exhaust_port_plans # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README
  • 16. MORE INFO THAN STATUS WITH DIFF $ git diff diff --git a/README b/README index e69de29..18ef097 100644 --- a/README +++ b/README @@ -0,0 +1 @@ +hello my empire minions - let's build a death star that works this time!
  • 17. NOW, COMMIT EVERYTHING ADDED TO THE STAGE $ git commit -m 'add exhaust port plans’ [master e8c1e22] add exhaust port plans 1 file changed, 1 insertion(+) create mode 100644 exhaust_port_plans SKIP THE STAGE AREA IF YOU DON’T NEED IT $ git commit -a -m 'add hello message to readme’ [master 73ceaf6] add hello message to readme 1 file changed, 1 insertion(+) REMOVE/MOVE FILES WITH $ git rm $ git mv
  • 18. IGNORE THINGS YOU CAN’T IGNORE ALREADY TRACKED FILES AN EXAMPLE OF THE .GITIGNORE TEXTFILE # a comment - this is ignored *.log .DS_store .idea/**/* **.classpath **.project **.settings (INSIDE THE PROJECTS ROOT DIRECTORY)
  • 19. RECAP RECORDING CHANGES CHECK CURRENT WORKING COPY STATUS $ git status ADDING FILES TO THE INDEX $ git add <pathspec> SHOW CHANGES $ git diff COMMIT TO REPOSITORY $ git commit [-a] [-m] (WORKING COPY INDEX)
  • 21. CHANGE YOUR LAST COMMIT –EX: ADD FORGOTTEN FILES $ git commit --amend NEVER AMEND AFTER YOU PUSHED YOUR CHANGES! UNSTAGE ADDED FILES $ git status # Changes to be committed: # # new file: alimony_for_luke $ git reset HEAD alimony_for_luke $ git reset HEAD alimony_for_luke # Untracked files: # # alimony_for_luke
  • 22. REVERT CHANGES IN YOUR WORKING DIRECTORY $ git status # Changes not staged for commit: # # modified: README # $ git checkout –- README $ git status # On branch master # nothing to commit, working directory clean
  • 23. REVERSE COMMIT $ git revert <commit> CREATES NEW COMMITS RECORDING THE REVERT CHANGES IF YOU GET MERGE CONFLICTS, RESOLVE AND CONTINUE $ git revert --continue CANCEL REVERT OPERATION $ git revert --abort
  • 24. RECAP UNDOING THINGS ALTER LAST COMMIT $ git commit --amend UNSTAGE FILES $ git reset HEAD <file> REVERT CHANGES $ git checkout -- <file> REVERSE COMMIT $ git revert <commit>
  • 26. ORIGIN LOCAL STASH WORKSPACE INDEX / STAGE REPOSITORY REPOSITORY CLONE STATUS STASH SAVE STASH POP STASH APPLY ADD COMMIT COMMIT -A MERGE REVERT CHECKOUT PUSH PULL FETCH
  • 27. YOUR CLONED REPO ALREADY HAS A REMOTE - ORIGIN $ git remote -v origin git@git.namics.com:deathstar-v3.git (fetch) origin git@git.namics.com:deathstar-v3.git (push) ADDING A REMOTE TO YOUR LOCAL REPOSITORY $ git remote add origin git@git.namics.com:deathstar-v3.git YOU COULD HAVE MULTIPLE REMOTES
  • 28. GETTING INFORMATION ABOUT A REMOTE $ git remote show origin * remote origin Fetch URL: git@git.namics.com:deathstar-v3.git Push URL: git@git.namics.com:deathstar-v3.git HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (fast-forwardable)
  • 29. FETCH VS PULL GET DATA FROM THE REMOTE REPOSITORY $ git fetch <remote-name> FETCH ONLY MANUAL MERGING FETCH $ git pull FETCH AND MERGE TRACKED BRANCHES PULL
  • 30. PUSH CHANGES PUSH BRANCH TO REMOTE $ git push <remote-name> <branch-name> ONLY WORKS IF NOBODY HAS PUSHED IN THE MEANTIME $ git push origin master Counting objects: 8, done. Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 650 bytes | 0 bytes/s, done. Total 6 (delta 0), reused 0 (delta 0) To git@git.namics.com:deathstar-v3.git 5d31566..73ceaf6 master -> master
  • 31. EXPLICITLY PUSH BRANCHES YOU WANT TO SHARE PUSH IS REJECTED IF CURRENT BRACH IS BEHIND $ git push origin master To git@git.namics.com:deathstar-v3.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@git.namics.com:deathstar-v3.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.
  • 32. RECAP REMOTES LIST REMOTES $ git remove -v ADDING REMOTES $ git remote add <shortname> <url> INFORMATION ABOUT REMOTE $ git remote show <shortname>
  • 33. RECAP REMOTES FETCH FROM REMOTES $ git fetch <remote-name> PULL FROM REMOTES $ git pull PUSH CHANGES TO REMOTES $ git push <remote-name> <branch-name>
  • 35. LIGHTWEIGHT VS ANNOTATED $ git tag v0.1 $ git tag –a v1.0 –m ‘first rel’ CHECKSUM IN A FILE FULL OBJECT INTERNAL PROJECTS CHECKSUM AUTHOR INFO GPG SIGNED (-s) OPEN SOURCE REPOSITORIES
  • 36. TAGS MUST BE PUSHED SEPARATELY $ git push origin --tags Total 0 (delta 0), reused 0 (delta 0) To git@git.namics.com:deathstar-v3.git * [new tag] 1.0 -> 1.0 LIST TAGS WITH $ git tag 1.0 1.1
  • 39. COMMITS AND BRANCHES COMMIT - OBJECT THAT CONTAINS A POINTER TO THE SNAPSHOT OF THE CONTENT THE GIT HISTORY IS A LINKED LIST OF POINTERS 98ca9 34ac2 f30ab Snapshot A Snapshot B Snapshot C
  • 40. A BRANCH IS A LIGHTWEIGHT POINTER TO A COMMIT LOCAL POINTER TO YOUR CURRENT BRANCH MASTER BRANCH POINTER 98ca9 34ac2 TESTING BRANCH POINTER HEAD master f30ab testing
  • 41. CREATING A BRANCH IS WRITING 41 BYTES TO A FILE (SHA-1 HASH PLUS NEWLINE) THAT’S WHY BRANCHING IS SUPER FAST
  • 42. CREATE A NEW BRANCH $ git branch testing CHECKOUT EXISTING BRANCH $ git checkout testing SWITCHING TAKES A BLINK OF THE EYE EVERYTHING HAPPENS IN YOUR WORKING COPY 98ca9 34ac2 NOW YOU’RE ON THE TESTING BRANCH SHORT FORM FOR BRANCH AND CHECKOUT $ git checkout –b testing master f30ab testing HEAD
  • 43. BASIC MERGING C0 I WANT TO MERGE ISS53 INTO MASTER Snapshot to Merge Into Common Ancestor C1 CHECKOUT THE TARGET BRANCH C2 master C4 C3 C5 $ git checkout master MERGE THE ISSUE BRANCH $ git merge iss53 iss53 Snapshot to Merge In
  • 44. master MERGE MAGIC HAPPENED: C0 C1 C2 THE RESULT $ git checkout master $ git merge iss53 C4 C3 C6 C5 iss53 Auto-merging README Merge made by the 'recursive' strategy. README | 1 + 1 file changed, 1 insertion(+) FEATURE BRANCH NO LONGER NEEDED, DELETE IT $ git branch –d iss53
  • 45. RESOLVING CONFLICTS WHAT IF MAGIC DOESN’T HAPPEN? CONFLICT (content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result. USE A MERGETOOL TO RESOLVE THE CONFLICTS $ git mergetool (DIFFMERGE FOR EXAMPLE)
  • 46. COMMIT CHANGES AFTER RESOLVING THE CONFLICTS $ git commit Merge branch 'testing' Conflicts: README # # It looks like you may be committing a merge. # If this is not correct, please remove the file # .git/MERGE_HEAD # and try again. THE MESSAGE IS AUTOGENERATED YOU CAN STILL EDIT IT OF COURSE
  • 47. RECAP MERGING CREATE BRANCH $ git branch <branchname> CHECKOUT BRANCH $ git checkout <branchname> MERGE BRANCHES $ git merge <commit> RESOLVE CONFLICTS $ git mergetool
  • 48. BRANCH MANAGEMENT LIST BRANCHES -a: remote branches $ git branch [--merged] [-a] DELETE BRANCHES $ git branch [-d] [-D] -D: force delete unmerged
  • 49. REMOTE BRANCH PUSHING TO REMOTE BRANCHES $ git push [remote] [branch] TRACKING REMOTE BRANCHES $ git checkout –b <branch> <remotename>/<branch> ALLOWS GIT PULL INSTEAD OF GIT FETCH DELETING REMOTE BRANCHES (NOTE THE : ) $ git push <remotename> :<branch>
  • 50. RECAP BRANCH MANAGEMENT LIST ALL BRANCHES $ git branch -a TRACKING REMOTE BRANCHES $ git checkout –b <branch> <remotename>/<branch> PUSHING TO REMOTE BRANCHES $ git push [remote] [branch] DELETING REMOTE BRANCHES (NOTE THE : ) $ git push <remotename> :<branch>
  • 51. BRANCHING WORKFLOWS GIT FLOW STRUCTURE FOR LARGE PROJECTS FEATURE BRANCH NEW BRANCH FOR EVERY FEATURE CENTRALIZED SVN LIKE FORKING USED BY GITLAB
  • 52. GIT FLOW MASTER OFFICIAL RELEASE HISTORY HOTFIX PRODUCTION RELASE PATCHING RELEASE POLISHING – NO NEW FEATURES DEVELOP FEATURE INTEGRATION FEATURE FEATURE DEVELOPMENT, CHILD OF DEVELOP
  • 54. REBASE A MERGING ALTERNATIVE TAKE ALL COMMITED CHANGES ON ONE BRANCH AND REPLAY THEM ON ANOTHER ONE
  • 55. SAME RESULT AS MERGE BUT CLEANER HISTORY IT APPEARS THAT ALL WORK HAPPENED IN SERIES B E F master C BEFORE A D experiment master AFTER A B E F C' D' experiment
  • 56. DO NOT REBASE PUSHED COMMITS REBASING ABANDONS EXISTING COMMITS AND CREATES SIMILAR NEW ONES USE REBASE IF YOU KNOW WHAT YOU’RE DOING NEWBIES SHOULD USE MERGE – IT’S SIMPLER REBASE A BRANCH ONTOP OF THE CURRENT ONE $ git rebase <branch> REBASE ONTO TARGET BRANCHES $ git rebase --onto <branches>
  • 58. SUBMODULES TRACKED BY THE EXACT COMMIT SPECIFIED IN THE PARENT REPOSITORY – LOCKED TO COMMIT GOOD FOR NOT TOO FREQUENT UPDATES THE WHOLE REPOSITORY IS INCLUDED AS SUBMODULE PARTIAL INCLUDE IS NOT POSSIBLE
  • 59. MANY BUTS’ LOTS OF DISADVANTGES AND PITFALLS YOU CAN’T JUST CLONE THE PARENT REPOSITORY SUBMODULE NEEDS TO BE INITIALIZED AND UPDATED NEVER AUTOMATICALLY UPDATED WHEN THE SUBMODULE REPOSITORY IS UPDATES YOU CAN’T BRANCH EASILY ACCIDENTIAL SUBMODULE REVERT HAPPENS EASILY LOTS OF THINKING INVOLVED WHEN USING SUBMODULES
  • 60. SUBTREE MERGE IT’S A MERGE STRATEGY (LIKE RECURSIVE FOR BRANCHES) NO NEW METADATA SUB-PROJECT CONTRIBUTION IS SLIGHTLY MORE COMPLICATED YOU ARE RESPONSIBLE FOR NOT MIXING SUPER AND SUB-PROJECT CODE
  • 62. INTERACTIVE MODE ENHANCED COMMAND LINE ADD –i TO COMMAND LINE; FOR EXAMPLE $ git add –i staged unstaged path 1: unchanged +0/-1 TODO *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now>
  • 63. THE STASH A “DIRTY LITTLE HELPER” STORE YOUR LOCAL MODIFICATIONS AWAY AND REVERT WORKING COPY TO HEAD COMMIT SAVE CHANGES TO STASH $ git stash APPLY STASH $ git stash pop
  • 64. ORIGIN LOCAL STASH WORKSPACE INDEX / STAGE REPOSITORY REPOSITORY CLONE STATUS STASH SAVE STASH POP STASH APPLY ADD COMMIT COMMIT -A MERGE REVERT CHECKOUT PUSH PULL FETCH
  • 65. CHERRY PICK APPLY CHANGES FROM ANOTHER COMMIT $ git cherry-pick <commit> BEFORE C0 C1 AFTER HEAD C2 C4 C0 C1 HEAD C2 C4 C6 git cherry pick C3 C3 C5 APPLY CHANGES FROM C3 AS NEW COMMIT ON TOP OF C4 C3 C5
  • 66. BISECT YOUR CODE FIND THE CHANGE WHICH INTRODUCED THE BUG $ git bisect start CURRENT VESION (HEAD) IS BAD $ git bisect bad LAST TESTED VERSION WHICH WAS GOOD $ git bisect good v0.4
  • 67. GIT SVN BIDIRECTIONAL OPERATIONS BETWEEN GIT AND SVN TRACK STANDARD SVN REPOSITORY “TRUNK/BRANCHES/TAGS” UPDATE GIT WITH FETCH $ git fetch UPDATE SVN WITH DCOMMIT $ git dcommit
  • 69. I CAN’T CLONE CHECK YOUR SSH CONNECTION $ ssh -T git@git.namics.com Welcome to GitLab, Daniel Kummer! VERIFY YOUR PUBLIC-KEY IN YOUR GITLAB PROFILE VERIFY YOUR PROJECT ACCESS IN GITLAB TRY RE-ADDING YOUR KEY TO SSH-AGENT $ ssh-add –D $ ssh-add ~/.ssh/id_rsa # deletes all identities in agent # add key to agent
  • 70. I CAN’T PULL VERIFY THAT THERE ARE NO UNCOMMITED CHANGES VERIFY THAT YOUR LOCAL BRANCH TRACKS A REMOTE ONE (TRACKED ONES ARE BLUE) $ git branch -vv * master 4658814 [origin/master] SUBSEQUENT TRACKING OF REMOTE BRANCHES $ git branch --set-upstream-to <local-branch> origin/ <remote-branch>
  • 71. I CAN’T PUSH CHECK IF YOUR LOCAL BRANCH IS BEHIND $ git push # Your branch is behind 'origin/master' by 5 commits CHECK IF YOUR LOCAL BRANCH IS TRACKING A REMOTE ONE
  • 72. I CAN’T DELETE A FILE FROM REPO TRY DELETING THE CACHED FILE ONLY (LEAVES WORKING COPY INTACT) $ git rm --cached eclipse.properties IF THE FILE NEEDS TO BE REMOVED FROM THE HISTORY $ git filter-branch … https://help.github.com/articles/remove-sensitive-data
  • 73. MORE MATERIAL GIT-PRO BOOK / REFERENCE http://git-scm.com/ TUTORIALS https://www.atlassian.com/git GIT FLOW CHEATSHEET http://danielkummer.github.io/git-flow-cheatsheet 15 MINUTES INTERACTIVE TUTORIAL http://try.github.io
  • 74. GETTING HELP $ git help <command> ASK YOUR LOCAL GURU GOOGLE IT CONT@CT ME