Super awesome custom command prompt os x and git branches

If you want to customize your command prompt in terminal on OS X it's super easy. A couple of things that I want to know at all times is where in the directory structure am I and also if I am working with in a project that is under git version control I want to know what branch I am working in. 

A lot of that is easy to find out by either issuing an "$ ls" command or "$ git branch", but I would rather save my self the key strokes and see where I am at in the command prompt. 

7nau
Open terminal and navigate to your home directory. If you are just opening terminal then it should open in your home directory but just to make sure you can type



cd ~/


After you are in your home directory you need to open your bash_profile witch is a hidden file on your system. If you do not have a .bash_profile you need to create one. I have textmate installed and usually open mine by typing

mate  ./.bash_profile
 

Once you open your .bash_profile you need the following lines in the file. I would suggest you put them below everything else if you already have statements in your file.



function parse_git_branch {
 ref=$( git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/') || return
 echo ${ref#refs/heads/}
}


RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"


export PS1="[ \W ]$YELLOW\$(parse_git_branch)$GREEN\$ "


After you save and close the file go back to your terminal window and type the following



source ~/.bash_profile


If all goes well you should have a better looking command prompt. 

 

More affordable git hosting

I for one think that github is extremely awesome for open source project hosting. However, it came time for me to find a better solution for hosting git repos for private projects. I never really looked at github pricing till just the other day. Holy shit it's expensive. I know cost can be subject to features and personal opinion but considering there are more inexpensive solutions for rolling your own repo hosting there was no way I was going to pull the trigger on a paid account.

After some searching around I pulled the trigger and signed up for an account with repositoryhosting.com. Why? Well yes I could have hosted repos on my own server but I have found that managing repos and more than one user can be a bit of a pain. Plus you get trac built in, witch is a great way of documenting and tracking your projects.

I get nothing at this point for pointing out this hosting solution other than the satisfaction of letting other developers know about a great service that is out there that will only run you $6 a month and you get the first 30 days to try it out for free.

Check out the features you get

Unlimited Repositories

Unlimited Trac Projects

Unlimited Users

Custom Domains

Custom Logos & Colors

SSL Secured

WebDAV Shared Drives

Scheduled Backups

2GB Storage

$1/GB Additional Storag

Updating a Github Fork from the Original Repository

Seems like everyone these days are switching from SVN to git. I think it's an awesome choose and I really like learning as much about git as I can. Something that is not quite clear when you are using github is how do you update a project that you have forked from someone else's repo? Well if you are like me I don't use git on a daily bases yet so I was not quite sure how this was done. After spending 10 min or so reading some blog posts this is what I found.

The following will only work if you have checked out a repo that you have forked and you have things setup correct. I am assuming that you have at least gotten as far as the basics of setting up git on your machine and you have forked someone else's code on github

First you need to add a remote branch to your repository that points to the original repo you forked from.

git remote add --track master benstucki git://github.com/benstucki/reflex.git

You will want to replace ‘master’ with the branch you want to track in the remote repo. In most cases this will be master, although you could replace it with edge or any other branch. You should also replace ‘benstucki’ is what you the remote will be called.

To verify the remote repository was added run

git remote

You should see the new remote repo, in this case named ‘benstucki’, along with any other remote repositories you may have previously added.

Now we can fetch all the changes from benstucki’s code base.

git fetch benstucki

This will create a new remote branch called ‘benstucki/master’. Now we are ready to merge the code from the remote repository.

git merge benstucki/master

That’s it. Remember, this process isn’t limited only to the original repository. Feel free to add remote branches for other user’s forks or even from repositories outside Github.

After you have followed the steps above all that is left to do is merge like so

git merge benstucki/master