Archive for the ‘branch’ tag
Git – Push a branch to remote repository
So you just created a new branch locally. You put in 200 hours into this branch, and then realize that the only copy of all these changes is on your MacBook! Don’t get scared, just push the branch to your remote server.
It’s easy:
$> git push -u <remote-name> <branch-name>
Or, usually:
$> git push -u origin branch-name
Add colored git branch name to your shell prompt
Here’s a little trick to get the name of your current git branch in your shell prompt. No more figuring out that you have made changes to the wrong branch once it’s too late! Your shell will not change for normal (non-git) folders. But, once you change directory into a git project, you will see the branch name added to your shell prompt like such:
Macintosh-2:git_project_foo andyuser [master] $
Simply add the following to your ~/.bash_profile or ~/.bashrc file:
function parse_git_branch_and_add_brackets {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
PS1="\h:\W \u\[\033[0;32m\]\$(parse_git_branch_and_add_brackets) \[\033[0m\]\$ "
That’s all there is to it ! Try it out !
