Skip to content

Instantly share code, notes, and snippets.

@skinny85
Forked from jbrodriguez/oneflow.md
Last active November 21, 2019 15:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save skinny85/a84d9cb2df703f96045869ec2582454b to your computer and use it in GitHub Desktop.
Save skinny85/a84d9cb2df703f96045869ec2582454b to your computer and use it in GitHub Desktop.
a git branching model (one branch / original + hybrid variant) WIP

oneflow

A flow based on this article

AR: my comments will start with four hashes

Original approach

Feature branches

 # let's update master with the latest changes from the remote 
git checkout master
git pull --rebase origin master

#### AR: A general comment. You shouldn't have any unpublished commits on your local master branch.
#### AR: If you do, you will accidentely push them when pushing the finished feature branch.
#### AR: That's why I would just do git fetch here, or just do git pull, without the --rebase
#### AR: switch, to make it clear. I probably wouldn't bother with a local master at all
#### AR: (or add some comment saying that you assume it's always without unpublished commits).

# Start work on a feature branch
git checkout -b feature/awesome

# implement awesome feature (feature 1, for example)

# commit changes
git add -A
git commit -m "add feature 1"

# ok i'm done with this feature branch, let's merge back to master
# first update master with latest changes from the remote
git checkout master
git pull --rebase origin master

# then merge the feature branch
git merge feature/awesome # deal with any merge conflicts here

# push to origin, remove branches
git push --tags origin master
git branch -d feature/awesome
git push origin --delete feature/awesome

#### AR: you're not tagging anything here, so no need for the --tags switch to git push

Release/Hotfix branches

# let's cut a release
git checkout master
# note we don't update master, since this is the point we've decided to base our release on

# Start work on the release branch
git checkout -b release/1.0.0

#### AR: I would simplify the description to something like:
#### AR: git checkout -b release/1.0.0 <the-commit-you-want-your-release-on>

# bump versions, add changelog, etc

# commit changes 
git add -A
git commit -m "Release 1.0.0"

# tag the release and push it to the remote
git tag 1.0.0
git push --tags origin master

#### AR: I believe this should be: git push --tags origin release/1.0.0 (you didn't update master)

# now we merge back to master
# first update our master from the remote
git checkout master
git pull --rebase origin master

# then do the actual merge
git merge release/1.0.0 # deal with merge conflicts here

# push to origin, delete release branch
git push --tags origin master
git branch -d release/1.0.0
git push origin --delete release/1.0.0

Hybrid approach

Feature branches

 # let's update master with the latest changes from the remote 
git checkout master
git pull --rebase origin master

# Start work on a feature branch
git checkout -b feature/awesome

# implement awesome feature (feature 1, for example)

# commit changes
git add -A
git commit -m "add feature 1"

# ok i'm done with this feature branch
# let's update from master by rebasing
git fetch origin
git rebase -i origin/master # deal with conflicts here

git checkout master
git pull --rebase origin master

# then merge the feature branch
git merge --no-ff feature/awesome # no conflicts here

# push to origin, remove branches
git push --tags origin master
git branch -d feature/awesome
git push origin --delete feature/awesome

Release/Hotfix branches

# let's cut a release
git checkout master
# note we don't update master, since this is the point we've decided to base our release on

# Start work on the release branch
git checkout -b release/1.0.0

# bump versions, add changelog, etc

# commit changes 
git add -A
git commit -m "Release 1.0.0"

# tag the release and push it to the remote
git tag 1.0.0
git push --tags origin master

# let's update from master by rebasing
git fetch origin
git rebase -i origin/master # deal with conflicts here

git checkout master
git pull --rebase origin master

# then merge the feature branch
git merge --no-ff release/1.0.0 # no conflicts here

# push to origin, remove branches
git push --tags origin master
git branch -d release/1.0.0
git push origin --delete release/1.0.0


#### AR: No No No No No. You cannot rebase neither release nor hotfix branches.
#### AR: If you do, you will either publish the current master, instead of just the
#### AR: release/hotfix work, or have duplicate commits in your repository (and weird 
#### dead-end branches for each release/hotfix). This always has to be done with a merge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment