Difference between revisions of "Git Flow"

From GLMWiki
Jump to: navigation, search
Line 64: Line 64:
 
== When to use support ==
 
== When to use support ==
 
These branches are just started and not intended to be merged back to master nor develop. This is usually fine, as fixes to "ancient" releases or features requested by customers to be implemented in "ancient" releases can't or should not go back into master. If you still think, you want to port a fix to your main development line (represented by master and develop), just start a hotfix, cherry-pick your changes and finish the hotfix.
 
These branches are just started and not intended to be merged back to master nor develop. This is usually fine, as fixes to "ancient" releases or features requested by customers to be implemented in "ancient" releases can't or should not go back into master. If you still think, you want to port a fix to your main development line (represented by master and develop), just start a hotfix, cherry-pick your changes and finish the hotfix.
 +
 +
 +
==Git Flow Process (example)==
 +
:This is merely an example. Things may not always follow this line of commands exactly. See also: [http://www.ashep.org/wp-content/uploads/2012/02/git-cheat-sheet-large.png Cheat Sheet 1], [https://source.android.com/images/git-repo-1.png Cheat Sheet 2], or [http://image.slidesharecdn.com/gitcheatsheet-131205141010-phpapp02/95/git-cheat-sheet-1-638.jpg?cb=1386274237 Cheat Sheet 3]
 +
 +
:(0. '''ssh-add''')
 +
::This is optional, to avoid having to enter your password every time you SSH into a remote server. Have a look at [https://www.debian.org/devel/passwordlessssh Setting up ssh to not need a password] if you care for such convenience.
 +
 +
:1. '''git clone p1 p2.''' <br/>
 +
::This is similar to svn checkout. You take the repository from the first parameter, and put it into the second. e.g.: '''git clone git@cvs2:web/mywebsite.git www.mywebsite.com'''. If you just want to update, and aren't making your first changes to a project, do '''git pull origin develop''' instead.[first do git flow init]
 +
 +
:2. '''cd www.mywebsite.com'''<br/>
 +
:: Go into the website's directory so that you can use git commands in the future.
 +
 +
:3. '''git flow init''' <br/>
 +
::You will be asked things. Just hit enter for master, develop, feature, release, hotfix and support, and on the final one type the letter V - this should only be necessary -once- the very first time anyone sets up the repository for the website.
 +
 +
:4. '''git branch -av'''  <br/>
 +
::This shows what branch you are on, as well as the branches that exist both locally and remotely. I think -av means show me All branches, and be Verbose.
 +
 +
:5. '''git checkout develop''' <br/>
 +
::Unlike SVN, this command merely changes the branch you're currently on to ''Develop''
 +
 +
:6. '''git flow hotfix start 1.0.3''' <br/>
 +
::This creates the hotfix branch called 1.0.3. Another example is '''git flow feature start AwesomeFeature'''. You will automatically be put into that branch, so that you will work from it.
 +
 +
-- start up your favorite editor and make whatever changes to whichever project/files you please --
 +
 +
:7. '''git status''' <br/>
 +
::This will show you all files that have been changed, and whether they are pending committing or adding.
 +
 +
:8. '''git add .''' <br/>
 +
::Be mindful of the period. This will make all files in all folders under the current directory ready for committing. To add a single file, for example: '''git add .htaccess'''.
 +
 +
:9. '''git commit''' <br/>
 +
::This will commit changes to the main branch. If you did this and forgot to change/add a certain file, simply do '''git commit --amend''' when you're ready.
 +
 +
:10. make liberal use of '''git status'''. <br/>
 +
::This will also show the command '''git reset HEAD <file> ''' to remove something you '''git add'''-ed in error (the command also works on folders). e.g. '''git reset HEAD .htaccess'''
 +
 +
:11. '''git flow hotfix finish '1.0.3'''' <br />
 +
::(this will bring you back to the develop branch and delete the hotfix branch after it merges its changes. Make note of your edits!)
 +
 +
::(*. '''git flow feature publish someFeature''' is another example, though '''publish''' doesn't remove the branch, it merely merges your changes with the main branch) <br/>
 +
::(*. Git may at some point complain about the fact that there are changes to wherever you're trying to commit/push to. It's merely a matter of doing '''git pull origin develop''' (where origin is the name of the branch you're taking it from, and develop is the branch you're taking it to) so that you're up-to-date!)<br/>
 +
::(*. '''git pull''' is really two commands combined into one: '''git fetch''' takes it from the main repository onto your ''remotes'' branch, then '''git merge''' takes it from ''remotes'' to whatever branch you indicated such as Develop or feature/someFeature <br/>
 +
::(*. This is also when you may realize you didn't yet start a branch, and you've already made changes. Have a look at '''git stash''', which will essentially put all changes into a separate stash. Then '''git flow feature start awesomeFeature''', which should put you on that branch, then do '''git stash pop''' to drop the stash onto that branch, after which the branch can be finished or published as noted above)
 +
 +
:10. '''git branch -av'''
 +
::Same command as before, to make sure what branch you're on.
 +
 +
:11. '''git push origin develop'''
 +
::This will send the committed changes to the remote main branch - this will push it TO origin FROM develop.
 +
 +
:12. '''gitk''' to marvel at a graphical representation of the good you've done today
 +
 +
:13. '''ssh ws6''' (or dev53 or whatever server), then '''cd /var/www/server/www.myweb'''~
 +
 +
:14. '''git pull origin develop'''
 +
::This has to be done for the changes you made, added, committed and pushed to actually have effect. This command may also be used on your own server, sort of like ''svn checkout'', instead of cloning at step 1. On WS6 you use '''git pull origin ''master''''' instead, since it only has a master branch.
 +
 +
:15. '''git pull --all'''
 +
::This will fetch all branches from origin and merge them with their tracking branches.
 +
 +
:16 '''git branch -u origin/develop develop''' && '''git branch -u origin/master master'''
 +
::setup your (local) branches as tracking branches (if you did git init)
 +
 +
 +
So, in summary, considering the repository has already been set up and you just want to make some changes: <br />
 +
'''git branch -av''' to see what branch you're on and which exist<br />
 +
'''git checkout develop''' to hop onto the branch called develop (this does not checkout like svn! git pull does that)<br />
 +
'''git pull origin develop''' to make sure your files are up to date, when you're in the website's directory. Most similar to svn checkout.<br />
 +
'''git flow feature SomeName''' to start a feature branch named SomeName<br />
 +
'''git flow hotfix 1.7.2''' to start a hotfix branch named 1.7.2<br />
 +
'''git status''' to see how your local file copies differ<br />
 +
'''git add someDir/someFile''' to add that file or folder to the list of things to be committed.<br />
 +
'''git reset HEAD someFile>''' to undo a git add, taking a file off the list of things to be committed.<br />
 +
'''git commit''' to commit changes to the branch. '''git commit --amend''' in case of last-minute additions<br />
 +
'''git push origin develop''' Send the committed changes ''from'' your Develop branch ''to'' the remote Origin branch.<br />
 +
'''gitk''' for a gui

Revision as of 08:58, 9 June 2016

Git Flow Workflow

git-flow

A successful Git branching model

Branches:

master => used for production code only

develop => used for developing new features (never ending)

hotfix => used for maintenance (get merged into master and develop once done)

release => used for creating new releases of code from the develop branch (merges back into master and develop)


to start an project clone the git repo and initialize the git flow

$ git clone git@cvs2:web/SooLocks.git www.soolocks.com
$ cd www.soolocks.com
$ git flow init -d

NOTICE: If others have been working on the project and have made a release or hotfixes before you you'll need to update all your branches. (usually your on only develop and only that is the one you are updating)

$ git pull --all

It helps to setup for local branches as tracking branches

$ git branch --set-upstream master origin/master
$ git branch --set-upstream develop origin/develop

git release

git flow release start v1.0 (then do your work and commit)
git flow release finish v1.0

git hotfix

git flow hotfix start v1.0.1 (then do your work and commit)
git flow hotfix finish v1.0.1

When you're done with either a hotfix or release you need to push all branches and tags

git push --all
git push --tags

NOTICE: it is wise to do a git pull first before you start with a release or hotfix

Tutorials

Git Flow

Cheat Sheets

http://danielkummer.github.io/git-flow-cheatsheet/

When to use develop

For new features or revamps.

When to use hotfix

Use a hotfix for doing any small site updates like graphic changes or text changes. These changes are typically not considered

usage:

$ git flow hotfix start "v1.1.6"

Do your work (text edits or other stuff.

$ git flow hotfix finish "v1.1.6"


When to use support

These branches are just started and not intended to be merged back to master nor develop. This is usually fine, as fixes to "ancient" releases or features requested by customers to be implemented in "ancient" releases can't or should not go back into master. If you still think, you want to port a fix to your main development line (represented by master and develop), just start a hotfix, cherry-pick your changes and finish the hotfix.


Git Flow Process (example)

This is merely an example. Things may not always follow this line of commands exactly. See also: Cheat Sheet 1, Cheat Sheet 2, or Cheat Sheet 3
(0. ssh-add)
This is optional, to avoid having to enter your password every time you SSH into a remote server. Have a look at Setting up ssh to not need a password if you care for such convenience.
1. git clone p1 p2.
This is similar to svn checkout. You take the repository from the first parameter, and put it into the second. e.g.: git clone git@cvs2:web/mywebsite.git www.mywebsite.com. If you just want to update, and aren't making your first changes to a project, do git pull origin develop instead.[first do git flow init]
2. cd www.mywebsite.com
Go into the website's directory so that you can use git commands in the future.
3. git flow init
You will be asked things. Just hit enter for master, develop, feature, release, hotfix and support, and on the final one type the letter V - this should only be necessary -once- the very first time anyone sets up the repository for the website.
4. git branch -av
This shows what branch you are on, as well as the branches that exist both locally and remotely. I think -av means show me All branches, and be Verbose.
5. git checkout develop
Unlike SVN, this command merely changes the branch you're currently on to Develop
6. git flow hotfix start 1.0.3
This creates the hotfix branch called 1.0.3. Another example is git flow feature start AwesomeFeature. You will automatically be put into that branch, so that you will work from it.

-- start up your favorite editor and make whatever changes to whichever project/files you please --

7. git status
This will show you all files that have been changed, and whether they are pending committing or adding.
8. git add .
Be mindful of the period. This will make all files in all folders under the current directory ready for committing. To add a single file, for example: git add .htaccess.
9. git commit
This will commit changes to the main branch. If you did this and forgot to change/add a certain file, simply do git commit --amend when you're ready.
10. make liberal use of git status.
This will also show the command git reset HEAD <file> to remove something you git add-ed in error (the command also works on folders). e.g. git reset HEAD .htaccess
11. git flow hotfix finish '1.0.3'
(this will bring you back to the develop branch and delete the hotfix branch after it merges its changes. Make note of your edits!)
(*. git flow feature publish someFeature is another example, though publish doesn't remove the branch, it merely merges your changes with the main branch)
(*. Git may at some point complain about the fact that there are changes to wherever you're trying to commit/push to. It's merely a matter of doing git pull origin develop (where origin is the name of the branch you're taking it from, and develop is the branch you're taking it to) so that you're up-to-date!)
(*. git pull is really two commands combined into one: git fetch takes it from the main repository onto your remotes branch, then git merge takes it from remotes to whatever branch you indicated such as Develop or feature/someFeature
(*. This is also when you may realize you didn't yet start a branch, and you've already made changes. Have a look at git stash, which will essentially put all changes into a separate stash. Then git flow feature start awesomeFeature, which should put you on that branch, then do git stash pop to drop the stash onto that branch, after which the branch can be finished or published as noted above)
10. git branch -av
Same command as before, to make sure what branch you're on.
11. git push origin develop
This will send the committed changes to the remote main branch - this will push it TO origin FROM develop.
12. gitk to marvel at a graphical representation of the good you've done today
13. ssh ws6 (or dev53 or whatever server), then cd /var/www/server/www.myweb~
14. git pull origin develop
This has to be done for the changes you made, added, committed and pushed to actually have effect. This command may also be used on your own server, sort of like svn checkout, instead of cloning at step 1. On WS6 you use git pull origin master instead, since it only has a master branch.
15. git pull --all
This will fetch all branches from origin and merge them with their tracking branches.
16 git branch -u origin/develop develop && git branch -u origin/master master
setup your (local) branches as tracking branches (if you did git init)


So, in summary, considering the repository has already been set up and you just want to make some changes:
git branch -av to see what branch you're on and which exist
git checkout develop to hop onto the branch called develop (this does not checkout like svn! git pull does that)
git pull origin develop to make sure your files are up to date, when you're in the website's directory. Most similar to svn checkout.
git flow feature SomeName to start a feature branch named SomeName
git flow hotfix 1.7.2 to start a hotfix branch named 1.7.2
git status to see how your local file copies differ
git add someDir/someFile to add that file or folder to the list of things to be committed.
git reset HEAD someFile> to undo a git add, taking a file off the list of things to be committed.
git commit to commit changes to the branch. git commit --amend in case of last-minute additions
git push origin develop Send the committed changes from your Develop branch to the remote Origin branch.
gitk for a gui