git overview

20
GIT Introduction - youEngineering

Upload: andy-ettisberger

Post on 15-Jul-2015

836 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Git Overview

GIT Introduction - youEngineering

Page 2: Git Overview

GIT key features

Own local repository

Branching is easy

Its fast

Working without connection to the central

repository

Page 3: Git Overview

GIT Configuration

Global git config —> .gitconfig

Project git config —> .git

Ignore files —> .gitignore

https://www.gitignore.io/ —> templates for

.gitignore

Page 4: Git Overview

GIT Areas

LOCAL

REPO

STAS

H

WORKSPA

CESTAGING UPSTREAM

REPO

YOUR LOCAL

COMMITS

YOUR FILES

READY TO COMMIT

LOCALLY

YOUR LOCAL

CHANGES

YOUR

TEMPORARY

BACKUP OF

CHANGES

Page 5: Git Overview

GIT Tools

GITK

UI showing your

local repository

GIT GUI

UI showing your

index

Page 6: Git Overview

unstaged

changes

staged

changes

content of

selected file

git gui

Page 7: Git Overview

history

changes in

files

file list of

selected

commit

gitk

Page 8: Git Overview

GIT Mergetool (for command line

user)

install p4merge

edit mergetool in .gitconfig

git mergetool

Page 9: Git Overview

Area - Stash

Place to save modifications if you wanna work on

something else

stash list show all stashes

stash pop pop last stash

stash apply [stash] apply stash from list

stash save [message] save stash with message

stash clear clear all stashes and lose your modifications

Page 10: Git Overview

Area - Workspace

Local checkout and working directory

git gui gui to watch your staging area

git status show status of your workspace

git diff show your local changes

git add . add all files to staging

git commit -a -m [message] add to staging and commit to

local repo in one command

Page 11: Git Overview

Area - Index/Staging

Staging area - files ready to get committed to local

repo

git status show status of your index

git commit -m commit staged files

git rm —chached [file] remove added file from index

git reset HEAD staged files are back to unstaged

git checkout [file] unstaged file will lose all changes

Page 12: Git Overview

Area - Local repo

Local repository

gitk show guy to track local commits

git push push local commits to repo

git reset HEAD^1 reset last commit to unstaged area

git reset —soft HEAD^1 reset last commit to staged area

git reset —hard HEAD^1 removes last commit, changes lost

git revert HEAD^1 creates a revert commit for the last local committed

changes

git revert [commitid] revert a specific commit - commit id can be tracked with

git log

Page 13: Git Overview

Area - Upstream repository

the actual repository on the server

git push push local commits to the upstream

git pull pull changes from upstream to the local

repository. If there are local changes you need to

stash them first or commit it locally

Page 14: Git Overview

Head, Master, Origin, wtf?

git branch -a shows local and remote branches

*master

remotes/origin/HEAD -> origin/master

remotes/origin/master

origin = remote repository name (default)

*master = local branch

remotes/origin/master = “remote” branch, last time checked!

head = pointer to the current commit, normally last commit in current

branch

Page 15: Git Overview

pull, fetch, merge, holy…

git pull = git fetch + git merge

git fetch = updates remote tracking branches in local

repository, you can do it always without losing your

working directory changes

after a fetch you can do: git diff master origin/master

to see what changed

git pull will then merge all changes into your local

directory

Page 16: Git Overview

fast forward merge?

default is always “fast forward”

if git detects that the remote branch didn't change

during your work on your local branch, it will just

point to the latest commit of your branch

if the remote branch changed, git will create a

merge commit

in the end: the history is different

Page 17: Git Overview

GIT Flows

Normal flow

git add . add current changes in the current directory

git commit -m “Test commit message” Commit to local repository

git push Commit to upstream repository

Amend commit

Idea: include new commit in already local committed changes

git commit —amend -m [message]

New commit will get “merged” into last local commit with the new commit

message

Page 18: Git Overview

GIT Flows

Normal update

git pull (= git fetch + git merge) get changes from

remote repo into local branch

git fetch only fetch changes to remote tracking

branches

git diff local_branch origin/master see fetched

changes

git merge merge fetched changes into local branch

Page 19: Git Overview

GIT Flows

Feature branches

git checkout -b new_feature_branch master creates feature branch

based on branch master

there is no difference between a master or another branch in the

repository

git push -u origin new_feature_branch push feature branch into the

upstream origin

git checkout master feature is finished, back to master branch

git merge new_feature_branch merge feature branch into master,

don't forget to check that you pulled everything from the master branch

so its definitely up2date

Page 20: Git Overview

GIT Flows

Merge commits between branches

git checkout some_branch change your current branch to

some_branch

we did some changes and committed it to the some_branch, now

we want to merge it into our some_other_branch

git log we look up the id of our last commit

git checkout some_other_branch change to our other branch

git cherry-pick ef4876c753c4e669fd2600d9c5b7447de729f3b3

cherry picks the commit and commit it to our current branch locally