Project

General

Profile

Enstore Git Flow Walk Through

*NOTE:
the examples below were executed against test repository

/cvs/projects/enstore-git-test

for production use

/cvs/projects/enstore

Install git flow scripts

from https://github.com/nvie/gitflow

checkout code from central repository

$ git clone ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test gitflow-test
Cloning into gitflow-test...
remote: Counting objects: 85737, done.
remote: Compressing objects: 100% (26388/26388), done.
remote: Total 85737 (delta 60735), reused 84138 (delta 59136)
Receiving objects: 100% (85737/85737), 53.12 MiB | 4.30 MiB/s, done.
Resolving deltas: 100% (60735/60735), done.

You will need to use proper repository URL when we switch to production (likely, replace two entries of 'enstore-git-test' by 'enstore'). The second argument gitflow-test is name of your local repository.

Production repository is :

git clone enstore ssh://p-enstore@cdcvs.fnal.gov/cvs/projects/enstore

Start working.

List remote and local branches:

$ cd gitflow-test

$ git branch -r
  origin/FILE_AGGREGATION_V1
  origin/FILE_AGGREGATION_V2
  origin/HEAD -> origin/master
  origin/encp_v3_6d
  origin/master
  origin/migration_package_based

$ git branch
* master
$ git checkout develop
Switched to branch 'develop'

Initialize gitflow

Chose name of branches. It detects existing branches in local repository, and suggests some choices.

$ git flow init

Change name for production branch if it asks:

Which branch should be used for bringing forth production releases?
   - develop
   - master
Branch name for production releases: [master] production

Which branch should be used for integration of the "next release"?
   - develop
   - master
Branch name for "next release" development: [develop]     

It may ask further questions if prefixes not set yet, agree with defaults, but set 'v_' as version tag prefix :

How to name your supporting branch prefixes?
Feature branches? [feature/] 
Release branches? [release/] 
Hotfix branches? [hotfix/] 
Support branches? [support/] 
Version tag prefix? [] v_  

Please check the configuration in you local .git directory if you have typos in branch names.
In my case

cat /opt/gitflow-test/.git/config
... some git configuration entries ...
[gitflow "branch"]
        master = production
        develop = develop
[gitflow "prefix"]
        feature = feature/
        release = release/
        hotfix = hotfix/
        support = support/
        versiontag = v_

Work on Feature

I created test "feature" on redmine using "New issue" tab above. The created feature has # 3830.

Now checkout code from central enstore redmine repository to you workstation to work on code.
Create new feature. The suggested name of the branch can be redmine feature ID followed by some short description:

$ git flow feature start 3830-test-feature-1-for-gitflow
Switched to a new branch 'feature/3830-test-feature-1-for-gitflow'

Summary of actions:
- A new branch 'feature/3830-test-feature-1-for-gitflow' was created, based on 'develop'
- You are now on branch 'feature/3830-test-feature-1-for-gitflow'

Now, start committing on your feature. When done, use:

     git flow feature finish 3830-test-feature-1-for-gitflow

$ cd src
$ pwd
/opt/gitflow-test/src

Create new source file:

$ cat > new-file-for-git-flow-test.py
#this is test file, can be deleted
^D

$ git add new-file-for-git-flow-test.py
$ git status
# On branch feature/3830-test-feature-1-for-gitflow
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    new file:   new-file-for-git-flow-test.py
#

$ git commit -m "adding new file new-file-for-git-flow-test.py" 
[feature/3830-test-feature-1-for-gitflow 70c117c] adding new file new-file-for-git-flow-test.py
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 src/new-file-for-git-flow-test.py

$ git status
# On branch feature/3830-test-feature-1-for-gitflow
nothing to commit (working directory clean)

Work locally, commit locallly.
Do code review. Publish the code to central repository to feature branch so others can see development milestones.

$ git flow feature publish 3830-test-feature-1-for-gitflow
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 399 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
 * [new branch]      feature/3830-test-feature-1-for-gitflow -> feature/3830-test-feature-1-for-gitflow
Already on 'feature/3830-test-feature-1-for-gitflow'

Summary of actions:
- A new remote branch 'feature/3830-test-feature-1-for-gitflow' was created
- The local branch 'feature/3830-test-feature-1-for-gitflow' was configured to track the remote branch
- You are now on branch 'feature/3830-test-feature-1-for-gitflow'

$ git branch -a
  develop
* feature/3830-test-feature-1-for-gitflow
  master
  production
  remotes/origin/FILE_AGGREGATION_V1
  remotes/origin/FILE_AGGREGATION_V2
  remotes/origin/HEAD -> origin/master
  remotes/origin/encp_v3_6d
  remotes/origin/feature/3830-test-feature-1-for-gitflow
  remotes/origin/master
  remotes/origin/migration_package_based

-- get to red mine
https://cdcvs.fnal.gov/redmine/projects/enstore-git-test/repository

select this new feature branch, see updated file there

Update code from remote repository to local git repository.

$ git fetch origin

Switch to develop branch, but it was not created yet on remote repository.

$ git checkout develop
Switched to branch 'develop'
$ git pull --rebase origin develop
fatal: Couldn't find remote ref develop
fatal: The remote end hung up unexpectedly

OK, fix it:
create branches on cdcvs (push local code to remote branch on cdcvs and call it 'develop.' It need to be created once, do not repeat.
Create production branch too.

$ git push origin develop
Total 0 (delta 0), reused 0 (delta 0)
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
 * [new branch]      develop -> develop

$ git checkout production
Switched to branch 'production'

$ git push origin production
Total 0 (delta 0), reused 0 (delta 0)
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
 * [new branch]      production -> production

$ git branch -a
  develop
  feature/3830-test-feature-1-for-gitflow
  master
* production
  remotes/origin/FILE_AGGREGATION_V1
  remotes/origin/FILE_AGGREGATION_V2
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/encp_v3_6d
  remotes/origin/feature/3830-test-feature-1-for-gitflow
  remotes/origin/master
  remotes/origin/migration_package_based
  remotes/origin/production

if you are using browser, click update to see the branch

Get production branch. Checkout feature branch. Rebase feature branch into production.

$ git checkout production
Already on 'production'
$ pwd
/opt/gitflow-test/src

$ git flow feature checkout 3830-test-feature-1-for-gitflow
Already on 'feature/3830-test-feature-1-for-gitflow'

$ git rebase develop
Current branch feature/3830-test-feature-1-for-gitflow is up to date.

$ git branch
  develop
* feature/3830-test-feature-1-for-gitflow
  master
  production

$ git flow feature rebase 3830-test-feature-1-for-gitflow
Will try to rebase '3830-test-feature-1-for-gitflow'...
Current branch feature/3830-test-feature-1-for-gitflow is up to date.

$ git flow feature publish 3830-test-feature-1-for-gitflow
Branch 'origin/feature/3830-test-feature-1-for-gitflow' already exists. Pick another name.

$ git flow feature 
* 3830-test-feature-1-for-gitflow

$ git flow feature help
usage: git flow feature [list] [-v]
       git flow feature start [-F] <name> [<base>]
       git flow feature finish [-rFkDS] [<name|nameprefix>]
       git flow feature publish <name>
       git flow feature track <name>
       git flow feature diff [<name|nameprefix>]
       git flow feature rebase [-i] [<name|nameprefix>]
       git flow feature checkout [<name|nameprefix>]
       git flow feature pull [-r] <remote> [<name>]


Do development, code reviews, publish code to you development branch on central repository.
When done:
$ git flow feature finish 3830
Switched to branch 'develop'
Updating 9b35b60..70c117c
Fast-forward
 src/new-file-for-git-flow-test.py |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 src/new-file-for-git-flow-test.py
Deleted branch feature/3830-test-feature-1-for-gitflow (was 70c117c).

Summary of actions:
- The feature branch 'feature/3830-test-feature-1-for-gitflow' was merged into 'develop'
- Feature branch 'feature/3830-test-feature-1-for-gitflow' has been removed
- You are now on branch 'develop'

Have a look where are we at local repository:

$ git branch
* develop
  master
  production

$ pwd
/opt/gitflow-test/src
$ ls -l new*
-rw-rw-r-- 1 aik aik 35 May  8 19:12 new-file-for-git-flow-test.py

$ git log  new-file-for-git-flow-test.py  
commit 70c117c47533a4143f0c0ba94f4be99dc77f7db7
Author: Alex <***@fnal.gov>
Date:   Wed May 8 18:37:37 2013 -0500

    adding new file new-file-for-git-flow-test.py

Work on Code Release

$ git flow release start 0.01
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to a new branch 'release/0.01'

Summary of actions:
- A new branch 'release/0.01' was created, based on 'develop'
- You are now on branch 'release/0.01'

Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

     git flow release finish '0.01'

Work on file

$ emacs -nw new-file-for-git-flow-test.py 

Try to publish release - it fails as changes in working directory were not saved to git. Save changes in local git repo.

$ git flow release publish my-release-0-01
fatal: Working tree contains unstaged changes. Aborting.

$ git commit -m "changed line in new-file-for-git-flow-test.py" new-file-for-git-flow-test.py
[release/0.01 e63e0be] changed line in new-file-for-git-flow-test.py
 1 files changed, 3 insertions(+), 0 deletions(-)

Publish changes to central repository so it becomes visible for others.

$ git flow release publish 0.01
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 406 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
 * [new branch]      release/0.01 -> release/0.01
Already on 'release/0.01'

Summary of actions:
- A new remote branch 'release/0.01' was created
- The local branch 'release/0.01' was configured to track the remote branch
- You are now on branch 'release/0.01'

$ git flow release list
* 0.01

You need to work on something else, release activity is not complete yet.

$ git flow feature pull origin 3830-test-feature-1-for-gitflow
Created local branch feature/3830-test-feature-1-for-gitflow based on origin's feature/3830-test-feature-1-for-gitflow.
$ git flow feature list
* 3830-test-feature-1-for-gitflow

Get back to release activity:

$ git checkout release/0.01
Switched to branch 'release/0.01'

$ cat new-file-for-git-flow-test.py
#this is test file, can be deleted

On release: 0.01 , add last minute fix
Now we done, and can publish release to production branch.

$ git flow release finish -p 0.01
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to branch 'production'
Merge made by recursive.
 src/new-file-for-git-flow-test.py |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 src/new-file-for-git-flow-test.py
Switched to branch 'develop'
Merge made by recursive.
 src/new-file-for-git-flow-test.py |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Deleted branch release/0.01 (was e63e0be).
Counting objects: 1, done.
Writing objects: 100% (1/1), 226 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
   9b35b60..9696966  develop -> develop
Counting objects: 1, done.
Writing objects: 100% (1/1), 228 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
   9b35b60..55d89c1  production -> production
Counting objects: 1, done.
Writing objects: 100% (1/1), 184 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
 * [new tag]         v_0.01 -> v_0.01
To ssh://p-enstore-git-test@cdcvs.fnal.gov/cvs/projects/enstore-git-test
 - [deleted]         release/0.01

Summary of actions:
- Latest objects have been fetched from 'origin'
- Release branch has been merged into 'production'
- The release was tagged 'v_0.01'
- Release branch has been back-merged into 'develop'
- Release branch 'release/0.01' has been deleted
- 'develop', 'production' and tags have been pushed to 'origin'
- Release branch 'release/0.01' in 'origin' has been deleted.

Meanwhile complete the toher work you were doing with feature branch you pulled.
When you do feature 'finish' the branch get merged: get merged:

$ git flow feature finish 3830
Already on 'develop'
Already up-to-date.
Deleted branch feature/3830-test-feature-1-for-gitflow (was 70c117c).

Summary of actions:
- The feature branch 'feature/3830-test-feature-1-for-gitflow' was merged into 'develop'
- Feature branch 'feature/3830-test-feature-1-for-gitflow' has been removed
- You are now on branch 'develop'