Git Workflow leads to Unsyncronized Branches on Bitbucket
I am fairly new to Git, get my ways around it though and basiclly everything is working the way I want it to be working. I just now ran into an issue involving Git, Bitbucket and the often cited “Successfull Git Branching Model”.
I have a local copy of my webproject and develop locally with Mamp Pro. Like I said I orientate myself on the “A successful Git branching model”, because it is seems well thought through and is often referenced in a lot of Git articles on the web.
When I am done with a hotfix or new feature I push to Bitbucket and in turn a POST Hook is being run that I create and manage with FTPloy (http://ftploy.com/).
Now, when I want to make a hotfix because something isn’t working on the website I go like this, assuming that Master and Staging are synced and up to date:
$ git checkout -b hotfix-5.0.20 master
I then fix the problem and commit it. The Successfull Branching Modell now says that the fix should first be merged back into master. I changed the workflow here, because I would rather first like to merge back into Development and then push it because this in turn updates dev.domain.com which is my Staging Enviroment running on the actual Liveserver. I want to do it like this to be able to check if everythings really fixed (and not breaking anything else in turn).
So I do this:
$ git checkout dev Switched to branch 'dev' $ git merge --no-ff hotfix-5.0.20 Merge made by recursive. (Summary of changes) $ git push origin dev
Then I check everything in Dev and if everythings fine I’ll do this:
$ git checkout master Switched to branch 'master' $ git merge --no-ff hotfix-5.0.20 Merge made by recursive. (Summary of changes) $ git push origin master
I’ll then delete the hotfix branch.
Now, here comes what’s throwing me off:
When I go to Bitbucket after doing the above steps and click onto “Branches”, Bitbucket tells me that the Developement Branch is one Commit behind and one Commit ahead. When I then click onto the Dev Branch and Sync it with Master, Bitbucket creates a new Commit and merges Dev with Master. When I go into that now last commit there will be no codechanges displayed, so it’s basiclly an empty commit.
I then have to pull in my local Git directory and from there on everything is in sync and up to date again.
Now, like I said I am fairly new to Git but I have a feeling that there is something wrong. I don’t want to do this manual syncing and pulling after committing every time and if I forget to do it I’ll end up with out of sync branches (at least in Bitbucket).
Is the solution probably as easy as branching off of Dev in the beginning, instead off Master?
Looking forward to your opinions and many thanks in advance!
OK, I just now tried to follow along precisly but came out with the same result. I am pretty sure it must be me doing something wrong. Please bear with me on this. I now did this:
$ git checkout -b hotfix-5.0.21 master
Made my changes, commited them.
$ git checkout master $ git merge --no-ff hotfix-5.0.21
$ git checkout development $ git merge --no-ff hotfix-5.0.21
$ git branch -d hotfix-5.0.21
$ git push
Bitbucket now shows the one behind, one ahead thing again… 🙁
One Solution collect form web for “Git Workflow leads to Unsyncronized Branches on Bitbucket”
If you look at your repository you’ll see that the merge command created two commits.
One commit was when you merged hotfix into dev. Another was when you merged hotfix into master. So because you have two different commits, BitBucket is showing out of sync.
You should be creating a hotfix branch off of master (you did), testing it independently and then merging back into master. When you test by merging it back into dev, you are testing on what could be a different code base. Once you are certain the hotfix works for your production code, then you deploy it and seek to apply the fix to development.
The only exception to this that nvie specifies is if a release branch exists.
You may also want to check out using git-flow to manage this process for you.