I’m finding it a bit difficult to memorize the correct procedure to create a new remote branch in git and start tracking it locally. This is a basic shell script that does it so that you don’t have to go through the procedure every time you want to create a new git branch.
Script
#!/bin/sh
# git-create-branch <branch_name>
if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 branch_name
exit 127
fi
branch_name=$1
git push origin master:refs/heads/$branch_name
echo "git push origin master:refs/heads/$branch_name"
git fetch origin
git checkout --track -b $branch_name origin/$branch_name
git pull
# git-create-branch <branch_name>
if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 branch_name
exit 127
fi
branch_name=$1
git push origin master:refs/heads/$branch_name
echo "git push origin master:refs/heads/$branch_name"
git fetch origin
git checkout --track -b $branch_name origin/$branch_name
git pull
Installation
Put this somewhere on your system and make it executable and create a symbolic link. I have it like this on my mac.
sudo ln -s /Users/Tinu/.bash_scripts/git-create-branch.sh /usr/local/bin/git-create-branch
Usage
As said in the script itself, use the script by git-create-branch <branch_name> inside a git repo in your system. Oh, you may want to create a bash alias too if you are that lazy like me.





November 25th, 2009 at 1:56 pm
Ваш пост навел меня на думки *ушел много думать* …