git hub « Intelligrape Groovy & Grails Blogs

Posts Tagged ‘ git hub ’

Using git diff feature on Github

Posted by on June 7th, 2011

Hi Folks,

Recently I came across a cool way to compare differences between two branches, two tags, or between two commits on Github. Many a times in our project we have to thoroughly see what has been a specific change in the code base before we push it on our production branch.

Here is how you can view the differences in commits:

On the Github, go to the Source view of your project. You will see a link named ‘Branch List’. Once the page opens you can see a list of all the remote branches. Hit on the Compare button in front of any of the available branches to see the difference between two branches.

Now note the URL in the address bar. It should end with something like ‘…/compare/<x>…<y>’ where x and y are separated by three dots(…) and their values could be project’s branch names

Isn’t it good?

Well, Git’s (read about git diff) and Github’s goodness does not stop just here. Instead of branch names as the values of x and y, you can also put two different commit hashes or tag names to view the differences in the code-base. More so, the commit hashes do not have to belong to the same branch. So you can pretty much compare your code’s current snap-shot with any of its past snap-shot irrespective of branch or a tag or a commit hash.

Hope this helps someone.

Abhishek Tejpaul
abhishek@intelligrape.com
[IntelliGrape Software Pvt. Ltd.]

Posted in System

Creating a New Git Branch on the Local Machine and Pushing it to a Remote

Posted by on September 9th, 2010

Our project went into production a few weeks back and was on Grails 1.3.1. Since the code was stable, we decided that it was time to upgrade to grails 1.3.4. However, we didn’t want to push it straight to the QA Server or Production server because that would’ve meant that the maintenance of the existing production code would become a pain.

To experiment with grails 1.3.4 and making sure that things were working smoothly, I’d created a new branch grails134, which was a copy of the master branch, which was deployed on production. After doing a grails upgrade and making some changes, we felt that a demo to the client and other developers was in order. Now, the issue was that I already had a new branch on the local machine and this needed to be pushed to the Git repository and the new branch tracked, so that we could push/pull changes to/from the new repository. I found this excellent post at David James’ blog on how to do this gracefully.

The tip under “Take Three” was the most helpful, as that was my use case.

The steps that I followed were :

  1. git checkout -b <new_branch_name>
  2. Make changes in the new branch
  3. git push origin <new_branch> //This pushes the new branch to the Git repository
  4. git checkout master //This was needed because git throws an error otherwise
  5. git branch -f <new_branch> origin/<new_branch> //The -f flag forces the recreation of the new_branch and tracks it to the remote, origin
  6. git checkout <new_branch>
  7. Start working on the new branch like we do with any normal branch and push changes to it.

With these steps, non-linear development was possible on multiple versions of grails in our project. Once the code base is stable for the new version, we intend to merge the changes from there to the master branch and delete this branch from the remote with the command:

git push origin :new_branch //This will delete the branch from the remote.
//We will need to delete the branch manually from the local machine

Hope this helps.

Vivek

http://in.linkedin.com/in/svivekkrishna

Posted in System

Git Stash : A very useful command

Posted by on August 31st, 2010

We have been using GitHub for version control in one of our projects and I am absolutely loving it! There are quite many advantages over a concurrent version control system like subversion.

One of the commands I found useful was the stash command. It is of use when we are working on a piece of functionality, which is not in a state to be committed, but find that there is a bug/issue in a previously committed piece of code and want to fix it before proceeding with any further development.

In that case, what we can do is issue the command

git stash save "work in progress"

Once that is done, it is a save point. Now you can revert the code for that particular branch by using the checkout command.
After fixing the issue and committing it (and pushing it) we can get back the copy on which we were working, with the command,

git stash pop

A very elegant command in what would’ve been an otherwise tedious job,

Hope this helps.

Vivek

http://in.linkedin.com/in/svivekkrishna

Posted in System