2. Init a project with existing files
git flow init
Creates two branches:
master (production release)
develop (next release)
Supported branches prefixes:
feature
release
hotfix
3. 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
4. git flow hotfix start my-hotfix
is equivalent to the next git commands
git checkout master
git branch hotfix/my-hotfix
git checkout hotfix/my-hotfix
or
git checkout -b hotfix/my-hotfix master
Starting a hotfix
5. git flow hotfix finish my-hotfix
is equivalent to the next git commands
git checkout master
git merge --no-ff hotfix/my-hotfix
git checkout develop
git merge --no-ff hotfix/my-hotfix
git branch -d hotfix/my-hotfix
don't forget to push master and develop into origin
git push origin [master|develop]
Finishing a hotfix
6. 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
7. git flow feature start my-feature
is equivalent to the next git commands
git checkout develop
git branch feature/my-feature
git checkout feature/my-feature
or
git checkout -b feature/my-feature develop
Starting a feature
8. git flow feature finish my-feature
is equivalent to the next git commands
git checkout develop
git merge --no-ff feature/my-feature
git branch -d feature/my-feature
don't forget to push develop into origin
git push origin develop
Finishing a feature
9. 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
10. git flow release start my-release
is equivalent to the next git commands
git checkout develop
git branch release/my-release
git checkout release/my-release
or
git checkout -b release/my-release develop
Starting a release
11. git flow release finish my-release
is equivalent to the next git commands
git checkout master
git merge --no-ff release/my-release
git tag -a my-release
git checkout develop
git merge --no-ff release/my-release
git branch -d release/my-release
don't forget to push master and develop into origin
git push origin [master|develop]
Finishing a release
12. Hotfixes
git checkout master
git pull
git checkout hotfix-branch
git merge master
Features
git checkout develop
git pull
git checkout feature-branch
git merge develop
What if my branch gets obsolete?
13. 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
14. 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
16. Log of the last 2 commits
git log -2
Differences in the last 2 commits
git log -2 -p
Differences between commits
git diff 77cf297..eb0df61
gif diff --name-only 77cf297..eb0df61f
git diff HEAD..HEAD^1 filename
Showing the last commits
17. Useful when we need to checkout another branch and we
don't still want to commit anything
git stash
git stash list
git stash pop
git stash apply stash@{0}
git stash show stash@{1}
git stash drop stash@{0}
Saving work without committing
18. If the file hasn't been added to the index
git checkout one.txt
If the file has already been added to the index
git reset HEAD one.txt
If we want to undo a commit but keeping the modifications
git reset --soft sha1_commit
If we want to undo a commit completely
git reset --hard sha1_commit
Throwing changes away
20. 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.txt
git commit --amend
21. Committing too early again
git add two.txt three.txt
git commit -m "my message"
I don't want the file three.txt in this commit
git reset HEAD^1 three.txt
git commit --amend
22. Fixing mistakes in previous commits
An error in the file four.txt was introduced in a previous commit
git checkout <SHA1_commit>
vim four.txt
git add four.txt
git commit --amend
git rebase --onto HEAD <SHA1_commit> <branch>
23. 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>