Search This Blog

Showing posts with label branch. Show all posts
Showing posts with label branch. Show all posts

Saturday, May 18, 2013

How to checkout Nova Folsom or Grizzly branch on github

Since Openstack Folsom release the source code is tracked on github. The previous releases like Essex, Diablo ... were maintained on Canonical Launchpad.

https://launchpad.net/nova/essex
https://github.com/openstack/nova

Problem

How to checkout Folsom release

Solution

We start with checking out latest nova code.
 
git clone git://github.com/openstack/nova.git
Cloning into 'nova'...
remote: Counting objects: 174497, done.
remote: Compressing objects: 100% (40106/40106), done.
remote: Total 174497 (delta 140401), reused 164045 (delta 130984)
Receiving objects: 100% (174497/174497), 116.95 MiB | 2.01 MiB/s, done.
Resolving deltas: 100% (140401/140401), done.

We can see what branches are available.
 
cd nova
 git branch
* master

At first it looks like something went wrong. We can see some tags although.
 
git tag
0.9.0
2011.1rc1
2011.2
...

To see all the branches (local and remote) we need to use -r or -a options.
 
git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/stable/folsom
  origin/stable/grizzly

git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/stable/folsom
  remotes/origin/stable/grizzly

When combining with -v we can see the last commits ID. We see that local master is the same as remotes/origin/master.
 
git branch -v -a
* master                        e4f05ba Imported Translations from Transifex
  remotes/origin/HEAD           -> origin/master
  remotes/origin/master         e4f05ba Imported Translations from Transifex
  remotes/origin/stable/folsom  6740c41 Check QCOW2 image size during root disk creation
  remotes/origin/stable/grizzly 159fdd2 Merge "Detach volume fails when using multipath iscsi"

We can see more info about the remote branch.
 
 git remote -v show origin
* remote origin
  Fetch URL: git://github.com/openstack/nova.git
  Push  URL: git://github.com/openstack/nova.git
  HEAD branch: master
  Remote branches:
    master         tracked
    stable/folsom  tracked
    stable/grizzly tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

To checkout a remote branch we use the standard checkout with -b options.
 
git checkout -b folsom  remotes/origin/stable/folsom
Checking out files: 100% (2510/2510), done.
Branch folsom set up to track remote branch stable/folsom from origin.
Switched to a new branch 'folsom'

git branch -a
* folsom
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/stable/folsom
  remotes/origin/stable/grizzly

 git branch -a -v
* folsom                        6740c41 Check QCOW2 image size during root disk creation
  master                        e4f05ba Imported Translations from Transifex
  remotes/origin/HEAD           -> origin/master
  remotes/origin/master         e4f05ba Imported Translations from Transifex
  remotes/origin/stable/folsom  6740c41 Check QCOW2 image size during root disk creation
  remotes/origin/stable/grizzly 159fdd2 Merge "Detach volume fails when using multipath iscsi" into stable/grizzly

As you can see it created a new local branch and set the pointer to the remote one. There is another way as well to do the same. We use the Grizzly branch to demonstrate this.
 
git checkout --track remotes/origin/stable/grizzly
Checking out files: 100% (2355/2355), done.
Branch stable/grizzly set up to track remote branch stable/grizzly from origin.
Switched to a new branch 'stable/grizzly'

git branch -a -v
  folsom                        6740c41 Check QCOW2 image size during root disk creation
  master                        e4f05ba Imported Translations from Transifex
* stable/grizzly                159fdd2 Merge "Detach volume fails when using multipath iscsi" into stable/grizzly
  remotes/origin/HEAD           -> origin/master
  remotes/origin/master         e4f05ba Imported Translations from Transifex
  remotes/origin/stable/folsom  6740c41 Check QCOW2 image size during root disk creation
  remotes/origin/stable/grizzly 159fdd2 Merge "Detach volume fails when using multipath iscsi" into stable/grizzly

git branch -a
  folsom
  master
* stable/grizzly
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/stable/folsom
  remotes/origin/stable/grizzly

Once we are done with the checking out we can always get back to the most up to date and latest code.
 
git checkout master
Switched to branch 'master'

References
  1. http://git-scm.com/book/ch3-5.html
  2. http://stackoverflow.com/questions/9537392/git-fetch-remote-branch

Wednesday, April 17, 2013

How to modify files in your branch on github

You created and released a new branch following the RERO development philosophy paradigm. Later on you discover that there are some bugs that you would like to fix in your branch and publish.

Problem

How to fix a file in a branch.

Solution

We need to checkout the branch from repository.
Modify the file and fix the issue.
Commit the changes back to our branch.

An example session is showed below.
 
git checkout challenge2
#now you modify the file, once done
git commit -m 'fixed delete_images func' -a
git push origin

# after modification we want to return in default branch
git checkout master
git branch

Monday, April 8, 2013

How to create a branch on github to freeze your code in a particular version

The nature of developing is that the code is in constant change. These could be new features, bug fixes, code refactoring or some modifications to polishing the code.

Sooner or later you are going to realize that on some occasions you need to have access and a reference to the code you tested or officially published. This is a big topic and I don't want to go into deep details about it. If you are interested to know more try to search on the web for Software Release Management topic.

As a simple example please take a look at my previous blog Challenge 1 script. I tested my code and documented the expected results. Some days after as I worked on the other scripts I made changes to my original code as well. For anyone who would like to take a look what I was describing previous it would be very difficult. Looking the latest code from github is not what you really want.

Problem

How to create a branch on github to release a particular version of your code.

Solution
 
$ git branch
* master
$ git checkout 47677b8c1cf79e6517b2caf7b32aca59b4d38795
HEAD is now at 47677b8... prints ipv4 ip

$ git branch
* (no branch)
  master

$ git branch challange1
$ git branch
* (no branch)
  challange1
  master

$ git checkout challange1
Switched to branch 'challange1'

$ git branch
* challange1
  master

$ git push origin challange1
Warning: Permanently added 'github.com,204.232.175.90' (RSA) to the list of known hosts.
Counting objects: 33, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (23/23), done.
Writing objects: 100% (33/33), 6.10 KiB, done.
Total 33 (delta 13), reused 15 (delta 4)
To git@github.com:rtomaszewski/api-challenge.git
 * [new branch]      challange1 - challange1

After the branch is created you can always download the code for it: https://github.com/rtomaszewski/api-challenge/tree/challange1

References
  1. https://github.com/Kunena/Kunena-2.0/wiki/Create-a-new-branch-with-git-and-manage-branches 
  2. http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging