Difference between revisions of "Git Flow"
From GLMWiki
Redirect page
(Redirected page to The Great GLM Git Guide#Git Flow) |
|||
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | #REDIRECT [[The Great GLM Git Guide#Git Flow]] | ||
+ | |||
[http://www.atlassian.com/git/workflows#!workflow-gitflow Git Flow Workflow] | [http://www.atlassian.com/git/workflows#!workflow-gitflow Git Flow Workflow] | ||
[http://github.com/nvie/gitflow git-flow] | [http://github.com/nvie/gitflow git-flow] | ||
− | + | [http://nvie.com/posts/a-successful-git-branching-model/ A successful Git branching model] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
to start an project clone the git repo and initialize the git flow | to start an project clone the git repo and initialize the git flow | ||
Line 27: | Line 20: | ||
git release | git release | ||
− | git release start v1.0 (then do your work and commit) | + | git flow release start v1.0 (then do your work and commit) |
− | git release finish v1.0 | + | git flow release finish v1.0 |
git hotfix | git hotfix | ||
− | git hotfix start v1.0.1 (then do your work and commit) | + | git flow hotfix start v1.0.1 (then do your work and commit) |
− | git hotfix finish v1.0.1 | + | 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 | When you're done with either a hotfix or release you need to push all branches and tags | ||
Line 42: | Line 35: | ||
== Tutorials == | == Tutorials == | ||
[http://www.youtube.com/watch?v=SChuTnuBYMg Git Flow] | [http://www.youtube.com/watch?v=SChuTnuBYMg Git Flow] | ||
+ | |||
+ | == Cheat Sheets == | ||
+ | http://danielkummer.github.io/git-flow-cheatsheet/ | ||
+ | |||
+ | == When to use master == | ||
+ | For production code only | ||
+ | |||
+ | == When to use release == | ||
+ | Used for creating new releases of code from the develop branch (merges back into master and develop) | ||
== When to use develop == | == When to use develop == | ||
Line 47: | Line 49: | ||
== When to use hotfix == | == When to use hotfix == | ||
− | Use a hotfix for doing any small site updates like graphic changes or text changes. | + | Use a hotfix for doing any small site updates and maintenance like graphic changes or text changes. |
These changes are typically not considered | These changes are typically not considered | ||
Line 59: | Line 61: | ||
== 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 |