Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Thursday, March 10, 2011

Create a Git Branch at a commit, Cherry-pick a commit

Git is very powerful and flexible. I simple love GIT

To create a new branch at a specific commit, is very simple

step1 : find out the Commit Point

$git log –oneline –decorate –graph

* 5da8d22 (HEAD, origin/master, origin/HEAD, master) adding the amazonfps versio
* 249e8f2 Remote the views and controllers files from plugin, first official rel
* 1859484 add some comments
* 51510a3 Moved the .git directory to inside from outside The plugin is now work
* ef5f694 initial checkin for amazonfps plugin
* 316cc21 removed mail.jar and mail jndi for morp support
* a7c2694 changed grailsplugin to comment jndimailsession, which was causing pro
* 9e9aab2 add the morph deploy jars
* b5c1b31 initial checkin
* 0ad0cd6 first commit

Step2 : BranchOut

git branch devbranch ef5f694

Will create a gitbranch at that commit point

Thursday, January 22, 2009

Working with Remote Branch on Git

I had two branches on github, one is master and other is trial, now when I clone I just get the master branch.
How do I get the trial branch, here are the commands

$ git branch -a //lists all branches on remote,
$ git checkout origin/trial //to preview the remote branch
$git checkout -b trial origin/trial //to clone the remote branch

$git branch //verify the local branches

Here is a good link on Git Remote Branches

Thursday, December 11, 2008

Using GIT with Amazon S3 on Windows

As I mentioned in my last blog, I was having some problems pushing changes to GITHUB, which have been resolved (I guess was due to my slow internet connection).
So I thought, we will give a shot to Amazon S3 and to my suprise we got it working in 30mins. OfCourse, it may be as powerful as GitHub in terms of features, but can be the cheapest way to maintain repositories

I did search for some these blogs which guided me,
http://www.tobinharris.com/2008/7/22/putting-git-in-the-cloud-with-amazon-s3
Also, tobharris has a excellent reference to Toolman Tim


Following are the steps are in detail on how to setup

  1. Signup for a Amazon S3 account , click here
  2. Install Jungle Disk, which will map your s3 storage to local drive say y:
  3. Install CYGWIN git and open it
  4. Go to y: from your MSysgit or Cygwin of your GIT, and perform following commands
  5. mkdir var/git/sample.git
  6. git --bare init
  7. go to your project directory, which needs to be pushed on sample.git
  8. git remote add s3origin /cygdrive/y/var/git/sampleajax.git
  9. git push s3origin master //This will push your project to master branch of s3origin
Testing if it on Windows
  1. Open Cygwin
  2. Go to say c:\temp
  3. mkdir sample
  4. cd sample
  5. git config --global user.email youremail
  6. git clone /cygdrive/y/var/git/sampleajax.git
Voila!! You are all setup with GIT on Amazon S3.

GIT and Amazon S3 combination can be used to make cheap backups as well as for maintaining projects.

Wednesday, December 10, 2008

GitHub Issues, GitHub Support

Github source repository is very good to store projects, but sometimes aftermaking lot of changes to my source code when I try to push the changes to repo back, I get the following error.

Not sure what the reason is, is it the size or something else. I have opened a ticket with GitSupport, once I recieve a response I will update it


$ git push origin master
Counting objects: 147, done.
Compressing objects: 100% (138/138), done.
Writing objects: 100% (146/146), 179.11 KiB, done.
Total 146 (delta 8), reused 0 (delta 0)
Read from remote host github.com: Software caused connection abort
fatal: The remote end hung up unexpectedly

I dont think size should be an issue as as 180Kb is not big


Finally, I was able to resolve this issue though mysteriously, after 5 hours when I tried to push again with a different internet connection at home, everything went smoothly. I guess it was a connection issues with my internet at office.

GitSuppot did try to help me out on this one, though they came little bit late to pitch in, they suggested to try msysgit instead of cygwin. If it had not worked, I would have give that a shot.

Monday, December 8, 2008

Git And GitHub Frequently Used Commads

GIT is a Distributed Version Control System, it is rapidly gaining popularity on other version control systems namely Subversion, CVS, due to its easy of use, and its rapid commit speed.
It creates a new way of adressing complexties on a OpenSource Project, where earlier developers had to wait for days to checkin their code and deal with complex merging issues.

With GIT, all those are things of the past, we can focus on pure business logic or the code we are concerned. We just have to merge the changes with trusted resources and not get bothered by tons of other people changes.

There are very excellent articles and videos which Cover GIT in detail, My goal here is to display those commands which our team has been using more often

Initialization Commands
  • git config --global github.user <>
  • git config --global user.email <>
  • git config --global color.branch "auto"
  • git config --global color.status "auto"
  • git config --global color.diff "auto"
  • git clone
General Commands
  • git log
  • git status
  • git diff, shows the difference between curret and head version
  • git diff "@{yesterday}" , shows changes since yesterday
  • dit whatchanged --since="2 weeks ago"
  • gitk, to open the git GUI
Branch Commads
  • git checkout -b $samplebranch , Creates a branch named samplebranch and switches to it
  • git checkout $samplebranch, Just switches to a new branch
  • git branch -d $branch, deletes the branch
  • git branch -a : shows all branches local and remote
  • git branch -r : show all remote branches
Remote Repo Commands
  • git remote add <remoterepo> git@github.com:>/>.git , Adds a remote repository (e.g forked one from the main) to your machine
  • git remote rm deletes the remote directory
  • git remote -v : displays all the remote repositories
Adding & Reverting & Commiting Changes on GIT
  • git add . , adds all the changed /new files to the repo
  • git reset --hard HEAD , Reverts all uncommited changes
  • git clean -df , Remove any files in your working directory that were not added to git e.g autogenerated files.
  • git revert , Reverts to previous commit.
  • git commit -m "my first commit" to commit the files
  • git checkout <>, to revert a individual file
Adding Tags at Regular Intervals
Its good to add tags lets say at different phases of project or while branching out,
  • git tag -a -m "branched out version1" version1 , this will tag the last commit with the tag version1
  • git tag , will display the tags
  • git push origin --tags , will push the tags to the remote origin
Pull and Merge Changes from other repos
The following steps summarize the commads need to pull changes from other forked branches to your local branch and push it to your remote github repo
  • git remote add auserepogit@github.com:auser/arepo.git
  • git remove -v
  • git checkout -b auser/master
  • git branch
  • git pull auserrepo master
  • git checkout master
  • git merge auser/master ,Note: if there are any conflicts open the files and resolve them
  • git add . , This step is need to add any resolved conflict files
  • git commit -m "your commits about successful merge"
  • git push origin master , to push your changes to the github origin repo
Creating Remote Branches
To create a remote branch, there are many ways to approach
  • Create a local branch
  • git push origin master:refs/heads/R1.2 : to create a branch name R1.2 on remote origin
  • git checkout -b R1.2
  • git pull origin R1.2 : to pull changes from remote R1.2 branch

Git Ignore
echo stacktrace.log >> .gitignore , adds stacktrace.log to .gitignore directory
Note: I haven't seen this working yet, hopefully soon it should work

Some Good Articles on GIT