theKindOfMe

April 7, 2011

Git Kung Fu

Filed under: Uncategorized — Tags: — yasi8h @ 1:40 am

These are some git commands that i find useful from time to time, but i forget them too often. So i am writing them down here. As a quick reference point.

Commits that needs to be pushed to remote X repo

git cherry -v origin/master

from: http://justinfrench.com/notebook/git-commits-that-need-to-be-pushed

Push a local branch to a remote branch with a different name

git push origin local_branch:remote_branch

Pull from a remote branch to a local branch with a different name

git checkout local_branch
git pull origin remote_branch

Merging
If you are in the middle of a merge (if you did a git pull and git merged what it can, automatically). You can go back your previous git pull stage by:

git reset --hard HEAD

Take their changes

git pull --strategy=theirs origin master

Take our changes

git pull --strategy=ours origin master

Start a web server to browse a git repository

cd /path/to/repo
git instaweb --httpd=webrick

The server will be running on localhost:1234. You omit the httpd parameter to let it use the default web server (which is lighthttpd btw), if its installed.

To stop it run:

git instaweb --httpd=webrick --stop

View more details about a branch

git show-branch branch_name

Remove and ignore already committed files from git

If you have a folder called .idea committed to your repo, and if you want to remove this from git and untrack it without actually deleting the files locally you could do this.

echo “.idea” >> .gitignore
git rm -r --cached .idea

-r – be recursive and –cached to not delete the actual files but just remove it from git’s index.
From: http://stackoverflow.com/questions/1329291/ignoring-an-already-checked-in-directorys-contents

I will be adding in to this post as i find new and interesting git ‘kung fu’ that i want to remember.

February 24, 2011

Git, Unfuddle and How to Use Multiple Key Files with SSH

Filed under: Uncategorized — Tags: , — yasi8h @ 1:16 pm

<rant> Unfuddle is a grate application. I use it daily. But one thing i really hate about it is that it requires you to use unique public keys. So you can’t use the same public key in two user accounts. Its all OK until you get work in a client’s unfuddle project. Where you will have a different account on the client’s unfuddle app. Boom! now you got to use another different key file just to work with any repo hosted in the client’s unfuddle app. This sucks big time. But the solution is not that complicated. </rant>

To use multiple key files with SSH (Git uses ssh internally),

  • Login to the machine/server from where you want to use git/ssh
  • Generate a key file (if you don’t already have one generated. But keep in mind you need a key file per account with unfuddle).
    • ssh-keygen
    • enter a name for the key
    • remember the name you entered!
  • Edit the ssh client config file
    • nano ~/.ssh/config
    • enter in the following lines (without the bullets of course!)
      • Host whatever.the.host.you.want.to.connect.to.here
      • IdentityFile=/path/to/your/key/file
    • The key file you specify in the Identity File directive is the private key (ie: not the key file with .pub extension).
  • Enter you public key to unfuddle
    • you can add your key in “Personal Settings”
    • your public key is the key that has a “pub” extension

Hope this helps. Even if no one else benifit from this i know i will someday 😀

Blog at WordPress.com.