Thursday, September 19, 2013

My notes for Git

This is my random notes to bookmark git commands for future reference.

Push/Pull a local repository to a remote git location

Lets take an example. I have my local repo pointing to openstack/neutron.git. I made some changes in my local repo and want to take backup before I send the code for review. I just need to add 'remote' location and push the code there.

git remote add githubbackup <url>

You can verify by looking into .git/config file if remote is added as expected.

Now push the code from master 

git push githubbackup master

If you want to pull the code from actual repo

git pull origin master

Similarly to pull from githubbackup 

git pull githubbackup master



For generating the patches from the topmost commits from a specific sha1 hash:
git format-patch -<n> <SHA1>
The last 10 patches from head in a single patch file:
git format-patch -10 HEAD --stdout > 0001-last-10-commits.patch