Skip to content

Instantly share code, notes, and snippets.

@ltfschoen
Last active September 9, 2017 01:57
Show Gist options
  • Select an option

  • Save ltfschoen/422c65b6844069734bc9e6dfd4dc92ce to your computer and use it in GitHub Desktop.

Select an option

Save ltfschoen/422c65b6844069734bc9e6dfd4dc92ce to your computer and use it in GitHub Desktop.
Git-Flow Workflow
* Install Git-Flow
```
brew install git-flow
```
* Git-Flow Help
```
git-flow help
usage: git flow <subcommand>
Available subcommands are:
init Initialize a new git repo with support for the branching model.
feature Manage your feature branches.
release Manage your release branches.
hotfix Manage your hotfix branches.
support Manage your support branches.
version Shows version information.
Try 'git flow <subcommand> help' for details.
```
* Initialise Git-Flow Repo
* Setup for existing repo
* If `master` branch already exists:
```
git flow init
Which branch should be used for integration of the "next release"?
- ...
- develop
- master
Branch name for production releases: [master] master
Which branch should be used for integration of the "next release"?
- ...
- develop
- master
Branch name for "next release" development: [master] develop
How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
```
* Setup with defaults
```
git flow init -d
Initialized empty Git repository in ~/myapp/.git/
Using default branch names.
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master]
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
```
* Note: The above adds to ~/myapp/.git/config
```
[gitflow "branch"]
master = master
develop = develop
[gitflow "prefix"]
feature = feature/
release = release/
hotfix = hotfix/
support = support/
versiontag =
```
* Create or use an existing remote repository (i.e. use [hub](https://github.com/github/hub) to generate Github repo using CLI instead of Github API due to [this](https://stackoverflow.com/questions/35124997/creating-github-repository-from-command-line))
* Add remote Git repository endpoint
```
git remote add origin git@github.com:myaccount/myrepo
```
* Retrieve latest changes from remote `master` Release branch.
Rebase the current branch on top of the upstream branch after fetching
```
git checkout master;
git pull --rebase=interactive origin master
```
* Interactively integrate the latest local Release branch into local Staging branch
```
git checkout develop;
git rebase -i master
```
* Start working on a feature1 for myapp using Git-Flow
```
$ git flow feature start feature1
Switched to a new branch 'feature/feature1'
Summary of actions:
- A new branch 'feature/feature1' was created, based on 'develop'
- You are now on branch 'feature/feature1'
```
* Note: Without Git-Flow `git checkout -b feature/feature1`
* Make changes to your codebase
* Show changes that were made:
```
git status
git diff
```
* Save changes to current branch
```
git add --all .
git commit -m "add feature1"
```
* Alternative using VIM: `git commit`; PRESS i; ENTER COMMENTS; PRESS ":wq" TO EXIT;
* Show history of changes in current branch
```
git log
```
* Share the local feature branch on a remote branch on the remote repository and configure the local branch to track the remote branch
```
git flow feature publish feature1
Already on 'feature/feature1'
Your branch is up-to-date with 'origin/feature/feature1'.
Summary of actions:
- A new remote branch 'feature/feature1' was created
- The local branch 'feature/feature1' was configured to track the remote branch
- You are now on branch 'feature/feature1'
```
* OPTIONAL create a Pull Request from the remote branch into remote `develop` branch
* Pull latest changes from a published remote branch to your local branch.
```
git flow feature pull origin feature1
git pull --rebase origin feature/feature1
Pulled origin's changes into feature/feature1
```
* Contribute to a remote branch that is not already a local branch
```
git flow feature track feature1
```
* Note: Without Git-Flow: `git fetch origin; git branch -a; git checkout feature/feature1;`
* OPTIONAL - Finalise a feature branch. Merge the feature into local `develop` branch and switch into it, remove the `feature1` branch
```
git flow feature finish feature1
Switched to branch 'develop'
Fast-forward
Deleted branch feature/feature1
Summary of actions:
- The feature branch 'feature/feature1' was merged into 'develop'
- Feature branch 'feature/feature1' has been removed
- You are now on branch 'develop'
```
* Note: Alternative without Git-Flow and retaining local branch `git checkout develop; git merge feature/feature1`
* References
* Comparison of Git-Flow with just Git https://gist.github.com/JamesMGreene/cdd0ac49f90c987e45ac
* Git-Flow usage example https://gist.github.com/seyhunak/0d4694fff198018ee5c4
* `git merge --no-ff` usage http://blog.jonathanoliver.com/my-new-best-friend-git-merge-no-ff/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment