SlideShare une entreprise Scribd logo
1  sur  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 !

Contenu connexe

Tendances

Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An IntroductionBehzad Altaf
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Simplilearn
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGeoff Hoffman
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash CourseNilay Binjola
 
Git Introduction
Git IntroductionGit Introduction
Git IntroductionGareth Hall
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeMd Swawibe Ul Alam
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of GitDivineOmega
 

Tendances (20)

Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git commands
Git commandsGit commands
Git commands
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
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
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Advanced Git Presentation By Swawibe
Advanced Git Presentation By SwawibeAdvanced Git Presentation By Swawibe
Advanced Git Presentation By Swawibe
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
Git 101
Git 101Git 101
Git 101
 

En vedette

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
 

En vedette (20)

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
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
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入門
 

Similaire à 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
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With GitNick Quaranto
 
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
 

Similaire à 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
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
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
 
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
 

Plus de 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
 

Plus de 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?
 

Dernier

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Dernier (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

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