I'm a team leader in our web development company, and I'd like to implement Git workflow in our team. Reading documentation and articles I've found the following structure good for us:
We have a repository in a Bitbucket. Master branch is considered to contain stable code only. Every dev must create his own branch and implement features/bugfixes in his own branch. Once he decides, that his code is ready, he creates a nice branch history (using rebase, amend, cherry-pick etc.) and pushes it to Bitbucket, where creates a pull request to master branch. QA verifies functionality and approves (or disapproves) it, then I'm verifying code and if it is ok, I merge his work into master (by fast-forward or rebasing for better commits history).
But this scheme is good only in a case, when single developer works on a branch. In our case we almost always have two developers for one branch, since one developer is working on server-side (PHP), and another - client-side (HTML/CSS/JS). How these two should collaborate in a way, that commit history in master stays clean?
Server dev creates basic structure of HTML files and client dev needs to get this structure. Logically would be for server dev to create a branch, and for client dev to create his own branch, based on server dev branch. But this means, that server dev needs to publish his branch in Bitbucket, which will make it impossible for him to rebase or change commits, that are already published.
Another option is to wait, until server dev finishes his work, publishes branch with nice commits history and forgets about it, and only after that client dev starts to work in this branch, but this will cause time delays, which is even worse.
How do you handle such a collaboration in your workflows?
You might see Git-flow this may help you
http://nvie.com/posts/a-successful-git-branching-model/
I think still nobody actually answered the original question of how to collaborate in topic branches maintaining a clean history.
The proper answer is sorry, you can't have all that together. You only can groom your private local history, after you publish something for others you should work on top of that.
The best you could do in your particular case where server dev doesn't care about client dev changes is to locally fork client branches from dev/feature ones and rebase that part on top of server work just before finishing the feature —or relax your constraints and switch to a different workflow, as you did ;)
We have a principal repository and each developer has a fork of that.
A branch is created principal/some_project, the same branch name is then created on each developers' fork, fork/some_project.
(We use smartgit and we also have a policy that remotes are named 'principal' and 'fork' rather than 'origin' and 'upstream' which just confuse new users).
Each developer also has a local branch named some_project.
The developers local branch some_project tracks the remote branch principal/some_project.
Developers do their local work on branch some_project and push-to to their fork/some_project, from time to time they create pull requests, this is how each developer's work gets merged into principal/some_project.
This way developers are free to pull/rebase locally and push to their forks - this is pretty much the standard fork workflow. This way they get other developers' commits and may from time to time have to resolve the odd conflict.
This is fine and all that's needed now is a way to merge in ongoing updates that appear in principal/master (for example urgent fixes or other projects that are delivered before some_project is finished).
To acomplish this we designate a 'branch lead' their role is to locally merge updates from master into some_project using merge (not pull, rebase) in SmartGit. This too may sometimes generate conflicts and these must be resolved. Once this is done that developer (the branch lead) force pushes to their fork/some_project branch then creates a pull request to merge into principal/some_project.
Once that pull request is merged, all of the new commits that were on principal/master are now present on the principal/some_project branch (and nothing was rebased).
Therefore the next time each developer is on some_project and pulls (recall, their tracked branch is principal/some_project) they'll get all of the updates which will include the stuff merged from principal/master.
This may sound long winded but it's actually fairly simple and robust (every developer could also just merge locally from principal/master but it's neater if one person does that, the rest of the team live in a simple world much like the single developer workflow).
Let me tell you what we do here while multiple developers working on the same project (even sometimes working on the same controllers/models/views).
First of all our team-lead created git-project with two branches
They told us to work on our local environment and create commits whenever we completed one of assigned task(s).
Now in the evening-time (or say closing time - leaving), we do this :
Every developer that are working on the same project Pull current development branch to their local (do same in morning - when starting for day).
Then team-lead told developer to commit all codes and push one by one followed by one pull.
For ex.
Now the problem is conflicts :
Now how to merge manually : GIT simply updates conflict files with all contents like this :
Team-lead updates that file after analyzing to this :
and creates commit and push.
Again in morning we do pull (just to make sure that we didn't miss anything from previous day), This is how we work here.
The rules to remember are:
master
and 1develop
branchdevelop
branchdevelop
develop
branchdevelop
master
, and create a tag for itFollowing diagram is the bull's eye strategy followed in teams across the world (Credit: taken from here):
This depends on your audience. "Server dev" can push the "basic structure" to Bitbucket so that "client dev" will have access to it. Yes this does potentially mean that others will have access to these "temporary" commits.
However this would only be an issue if another user branched from one of these commits before they were rebased. On a smaller project/smaller userbase these temporary commits might never be noticed even before the rebase occured, hence negating the risk.
The decision is yours if the risk of someone branching from these temporary commits is too great. If so then you would need to perhaps create a second private Bitbucket repo for these private changes. Another option would be to do merge commits instead of rebasing, but this is also not ideal.