Git and git flow

Post on 11-Jan-2017

526 views 2 download

Transcript of Git and git flow

Git flow & Git

Init a project with existing files

git flow init

Creates two branches:master (production release)develop (next release)

Supported branches prefixes:featurereleasehotfix

After finishing "my-hotfix", master and develop have the commits made in the hotfix branch

Hotfixes workflow

Command master my-hotfix develop

git flow hotfix start my-hotfix

working in hotfix

git commit -am "msg"

git flow hotfix finish my-hotfix

git flow hotfix start my-hotfix

is equivalent to the next git commands

git checkout mastergit branch hotfix/my-hotfixgit checkout hotfix/my-hotfix

or

git checkout -b hotfix/my-hotfix master

Starting a hotfix

git flow hotfix finish my-hotfix

is equivalent to the next git commandsgit checkout mastergit merge --no-ff hotfix/my-hotfixgit checkout developgit merge --no-ff hotfix/my-hotfixgit branch -d hotfix/my-hotfix

don't forget to push master and develop into origingit push origin [master|develop]

Finishing a hotfix

After finishing "my-feature", only develop has the commits made in the feature branch

Features workflow

Command master my-feature develop

git flow feature start my-feature

working in feature

git commit -am "msg"

git flow feature finish my-feature

git flow feature start my-feature

is equivalent to the next git commands

git checkout developgit branch feature/my-featuregit checkout feature/my-feature

or

git checkout -b feature/my-feature develop

Starting a feature

git flow feature finish my-feature

is equivalent to the next git commands

git checkout developgit merge --no-ff feature/my-featuregit branch -d feature/my-feature

don't forget to push develop into origingit push origin develop

Finishing a feature

After finishing "v2.0", master and develop have the commits made in the release branch

Releases workflow

Command master v2.0 develop

git flow release start v2.0

working in release

git commit -am "msg"

git flow feature finish v2.0

git flow release start my-release

is equivalent to the next git commands

git checkout developgit branch release/my-releasegit checkout release/my-release

or

git checkout -b release/my-release develop

Starting a release

git flow release finish my-release

is equivalent to the next git commandsgit checkout mastergit merge --no-ff release/my-releasegit tag -a my-releasegit checkout developgit merge --no-ff release/my-releasegit branch -d release/my-release

don't forget to push master and develop into origingit push origin [master|develop]

Finishing a release

Hotfixesgit checkout mastergit pullgit checkout hotfix-branch git merge master

Featuresgit checkout developgit pullgit checkout feature-branchgit merge develop

What if my branch gets obsolete?

git flow [hotfix|feature|release] publish my-branch

you can checkout remote branches like this

git checkout -b my-branch origin/my-branch

don't forget to remove them when they are not needed anymore

git push origin :my-branch

Publishing remote branches

Suitable to support old versions of the software but in a very EXPERIMENTAL status and NOT RECOMENDABLE for production environments

git flow support start v1.1.1 v1.0

Support branches

Useful git commands

Log of the last 2 commitsgit log -2

Differences in the last 2 commitsgit log -2 -p

Differences between commitsgit diff 77cf297..eb0df61gif diff --name-only 77cf297..eb0df61fgit diff HEAD..HEAD^1 filename

Showing the last commits

Useful when we need to checkout another branch and we don't still want to commit anything

git stashgit stash listgit stash popgit stash apply stash@{0}git stash show stash@{1}git stash drop stash@{0}

Saving work without committing

If the file hasn't been added to the indexgit checkout one.txt

If the file has already been added to the indexgit reset HEAD one.txt

If we want to undo a commit but keeping the modificationsgit reset --soft sha1_commit

If we want to undo a commit completelygit reset --hard sha1_commit

Throwing changes away

Fixing mistakes with git

Committing too early

git commit -m "my message"

I forgot to add the file one.txt and I don't want to do another commit

git add one.txtgit commit --amend

Committing too early again

git add two.txt three.txtgit commit -m "my message"

I don't want the file three.txt in this commit

git reset HEAD^1 three.txtgit commit --amend

Fixing mistakes in previous commits

An error in the file four.txt was introduced in a previous commit

git checkout <SHA1_commit>vim four.txtgit add four.txtgit commit --amendgit rebase --onto HEAD <SHA1_commit> <branch>

Recovering local deleted branch

git branch -D my-feature

Looking for the last commit in the deleted branch and getting its SHA1 with git reflog

git branch my-feature <sha1_last_commit>

Links

● http://git-scm.com/documentation

● http://nvie.com/posts/a-successful-git-branching-model/