GitFlow Cheat Sheet

September 8, 2016

Installing GitFlow on Windows

  1. Install cmder. Google it. Make sure you get the git for windows version.
  2. Download and install in C:\Program Files\Git\bin

a) getopt.exe from util-linux-ng package from the Binaries zip folder found at http://gnuwin32.sourceforge.net/packages/util-linux-ng.htm

b) libintl3.dll from libintl package from the Binaries zip folder found at http://gnuwin32.sourceforge.net/packages/libintl.htm

c) libiconv2.dll from libiconv2 package from the Binaries zip folder found at http://gnuwin32.sourceforge.net/packages/libiconv.htm

  1. Start cmder, which is a better command prompt console. Change folder to the one that you want to install gitflow in. It will install a gitflow folder under this.
cd c:\users\Tony

4. Clone the gitflow repository.

git clone –recursive git://github.com/nvie/gitflow.git 

5. Change to the gitflow folder

cd gitflow
  1. Install gitflow, using the following command:
Contrib\msysgit-install.cmd “c:\Program Files\Git\”

 

Installing GitFlow in a repository

  1. Create your project folder: mkdir c:\demos\flow
  2. Change directory to the project folder: cd c:\demos\flow
  3. Initialise an empty Git repository: git init
  4. Initialise the repository for GitFlow: git flow init

Choose all the defaults.

The prompt should change show that you are in the c:\demos\flow (develop) branch.

  1. Checkout the master branch
git checkout master
  1. Make sure you have set up a repository on GitHub. On the github repository page, click on the Clone or download button and then click on the Use SSH link in the top right hand corner. Copy the link. Then execute the git remote command to set up the origin in git:
git remote add origin git@github.com:tonywr71/PSGitFlow.git
  1. Now push the origin to the master, to establish the github connection
git push –u origin master
  1. Change back to the develop branch
git checkout develop
  1. Now push the develop branch
git push origin develop
  1. If you go back to the repository page, you should now be able to select the two branches from the Branch drop down.

 

Creating a Feature Branch

  1. Make sure you have cloned the repository into a destination directory
git clone git@github.com:tonywr71/PSGitFlow.git .

Note the period (.) which is used to force it to be installed in the current directory, not a child of the current directory.

It will put you in the (master) branch

  1. Change to the develop branch
git checkout develop
  1. Initialise gitflow in the new folder if it hasn’t been done already
git flow init

and select all the defaults

  1. Go into github for this repository and select the Issue tab. We want the new feature to be associated with the issue. So add a new issue for the feature. The Issue number and issue subject should be part of the new feature name. The Issue Subject here would be “Users Can Access Single Entries” for example.
  2. Add a new feature branch
git flow feature start 2-UsersCanAccessSingleEntries

where 2 is the Issue number and UsersCanAccessSingleEntries is a concatenation of the issue subject. The command prompt will now show the feature branch:

c:\demos\tony (feature/2-UsersCanAccessSingleEntries)

  1. This branch hasn’t been pushed back into the repository yet, so there is no tracking in github. If you make changes to code in this folder, the prompt will now be highlighted in red, to show changes pending. If you want to see the pending changes, execute:
git status
  1. To add the files into git
git add .
  1. To commit the repository locally, with a message:
git commit –am “Added code to get single entry”

This will change the command prompt folder back to white and commit the changes locally.

  1. To add the feature back onto the central repository
git flow feature publish 2-UsersCanAccessSingleEntries
  1. If you go into github, you can now select the feature branch from the Branch drop down

 

Reviewing a feature branch on another machine (or in another folder on the same machine)

  1. To see the list of feature sub-commands in gitflow:
git flow feature help
  1. To pull the feature into my local repository, switch you into that branch, but don’t track changes:
git flow feature pull 2-UsersCanAccessSingleEntries
  1. To pull the feature into my local repository, switch you into that branch and track changes to that feature:
git flow feature track 2-UsersCanAccessSingleEntries
  1. Make your changes in the tracked folder. In Cmder the command prompt will show a red feature folder. Again, you can see the pending changes by executing:
git status
  1. Add the files that have been changed:
git add .
  1. Then commit them to the local repository with message:
git commit –am “Added exception handling”
  1. Finally, to push them to the central repository:
git push

 

Get the reviewers changes back on the originator’s machine

  1. Check out the feature and pull it.
git pull

 

Finishing the Feature Branch and merging back into the develop branch

  1. The developer closes the branch, not the reviewer. The developer would click the Merge pull request button to merge back with the develop branch. The reviewer Closes the pull request, but doesn’t finish it. To finish the feature, the developer executes:
git flow finish 2-UsersCanAccessSingleEntries
  1. The feature branch is now deleted both locally and remotely, and you will have been switched back to the develop branch.
  2. Other developers that are using this feature will also need to delete their local branch. That is done by executing:
git checkout develop
git branch –d 2-UsersCanAccessSingleEntries
  1. To check it has been removed
git branch

should no longer be showing the feature branch.

 

Creating a Release Branch

  1. This is the point in time where a release is ready.
  2. Once the Release Branch is created, it is passed to QA for testing.
  3. Any bugs that are found on the release branch will need to be fixed on the Release Branch and then merged back into the develop branch, so that any future feature branches will pick up those fixes.
  4. The architect creates the Release Branch by executing:
git flow release start sprint1-release
  1. The command prompt will show the new release folder, but this branch is currently only on the local machine. To publish this release so everyone can access it:
git flow release publish sprint1-release
  1. If you go into github and pull down the Branch drop down, you will see the new Release Branch.

 

Reviewing a Release Branch

  1. To view and track the release on someone else’s machine, set up a folder on that machine and execute:
git flow release track sprint1-release
  1. If someone makes changes to files in that branch, you can check the changes using
git status
  1. You can then add any changes to the local repository
git add .
  1. Then commit the changes to the local repository
git commit –am “Add logging to exception (example message)”
  1. Then push the change to the remote repository
git push
  1. The changes are now in the Release Branch, but need to be merged back to the develop branch.
git checkout develop
  1. Pull the develop branch
git pull
  1. Then merge it with the release branch
git merge release/sprint1-release
  1. That merge is local, so we now need to push changes back to the develop branch
git push 

 

Cleaning up the Release Branch and pushing to the master branch

  1. This job is done by the Architect, who will change to the Release Branch
git checkout release/sprint1-release
  1. Do a pull to make sure the local machine is up-to-date
git pull
  1. Now finish the release
git flow release finish sprint1-release

This will merge our flow back into the master branch and open up an emacs text editor to allow us to enter a more substantial release note. Save the text editor and exit. The release will be merged into the master branch and tagged with the release name. The tag is also back-merged into the develop branch. The release branch is also deleted both locally and remotely, and you are switched back to the develop branch.

  1. At this time, the develop branch is still checked out, so we need to change back to the master branch to check it all in.
git checkout master

When executing this command it will tell you how many commits there are difference between the master and the develop branch.

  1. We need to push all these changes including all the tags back to the remote repository.
git push –-tags

 

Creating a HotFix

  1. A Hot Fix is an emergency fix to released code. The Hot Fix is created on the master (production) branch. After making the fix on the Hot Fix Branch, it is then merged back into the master and develop branches.
  2. On the machine where the fix needs to occur, start the hotfix
git flow hotfix start hotfix1

Note that hotfix1 should match an issue in GitHub

  1. You will now be in the hotfix branch. Make changes to this branch and you can see the changes to the branch by typing
git status
  1. Once the hotfix has been finished, the changes need to be committed:
git commit –am “Hot fix changes”
  1. The developer can then finish the hotfix by executing
git flow hotfix finish hotfix1

This will bring up the emacs text editor and you can add a hotfix release note, then save and close the editor and it will merge the hotfix into the master, tag it as hotfix1, back merge that tag into the develop branch, deleted the local hotfix1, and switch you into the develop branch.

  1. To see how many commits are outstanding on the develop branch, type
git status
  1. You can also switch to the master branch and see where that is
git checkout master
git status
  1. To push changes back to both remote branches, execute:
git push –-all origin