Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed copy/paste error about fast-forwards

...

Code Block
languagetext
titleCreating the Feature Branch
$ git checkout -b branch-feature-AMBARI-12345 trunk
Switched to a new branch 'branch-feature-AMBARI-12345'

$ git push -u origin branch-feature-AMBARI-12345
Total 0 (delta 0), reused 0 (delta 0)
To https://git-wip-us.apache.org/repos/asf/ambari.git
 * [new branch]      branch-feature-AMBARI-12345 -> branch-feature-AMBARI-12345
Branch branch-feature-AMBARI-12345 set up to track remote branch branch-feature-AMBARI-12345 from origin by rebasing.

...

  • Branch is correctly named

...

  • Branch is pushed to Apache so it can be visible to other developers

 

Code Block
languagetext
titleCommitting to Your Feature Branch
$ git checkout -b branch-feature-AMBARI-12345 trunk
Switched to a new branch 'branch-feature-AMBARI-12345'

$ git add <some-file>
$ git commit -m 'AMBARI-28375 - Some Change (me)'

$ git add <some-file>
$ git commit -m 'AMBARI-28499 - Another Change (me)'

$ git push

...

  • Each commit to the feature branch has its own AMBARI-

...

  • XXXXX JIRA

  • Multiple commits are allowed before pushing the changes to the feature branch

 

Code Block
languagetext
titleMerging Trunk into Feature Branch
$ git checkout branch-feature-AMBARI-12345
Switched to branch 'branch-feature-AMBARI-18456'
 
$ git merge trunk
Updating ed28ff4..3ab2a7c
Fast-forward
 ambari-server/include.xml | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 ambari-server/include.xml

...

  • Merging trunk into the feature branch often (daily, hourly) allows for faster and easier merge conflict resolution

...

  • Fast-forwards are OK here since trunk is always the source of truth and we don't need extra "merge" commits in the feature branch

 

Code Block
languagetext
titleMerging Feature Branch Into Trunk
$ git checkout trunk
Switched to branch 'trunk'
 
$ git merge --no-ff branch-feature-AMBARI-12345
Updating ed28ff4..3ab2a7c
 ambari-server/include.xml | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 ambari-server/include.xml
Info
titleNo Fast-forwards

Notice that the --no-ff option was provided when merging back into trunk. This is to ensure that an additional "merge" commit is created which references all feature branch commits. With this single merge commit, the entire merge can be easily backed out if a problem was discovered which destabilized trunk.

...

  • The feature is merged successfully with a "merge" commit back to trunk

...

  • This can be done multiple times during the course of the feature development as long as the code merged back to trunk is stable

 

Code Block
languagetext
titleDeleting Your Branch
$ git checkout trunk
Switched to branch 'trunk'
 
$ git branch -d branch-feature-AMBARI-12345
Deleted branch branch-feature-AMBARI-12345 (was ed28ff4).
 
$ git push origin --delete branch-feature-AMBARI-12345
To https://git-wip-us.apache.org/repos/asf/ambari.git
 - [deleted]         branch-feature-AMBARI-12345
 
$ git remote update origin --prune
Fetching origin
From https://git-wip-us.apache.org/repos/asf/ambari
 x [deleted]         (none)     -> branch-feature-AMBARI-56789

...

  • Cleanup the branch when done, both locally and remotely

...

  • Prune your local branches which no longer track remote branches