4

Useful script for working with remote branches in git

 2 years ago
source link: https://markshust.com/2011/12/28/useful-script-working-remote-branches-git/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Useful script for working with remote branches in git

December 28, 2011   ·   1 min read  ·   Edit on GitHub

Working with git using remote branches is a great tool to manage workflow and coordinating code with other developers. However, the commands you need to remember could be quite daunting and even hard to remember for the experienced programmer. I created a simple script at github called git-remotebranch. A copy of the script is below (please see github for the latest and greatest). Just chmod it 777, throw it in your /etc/init.d/ folder (or another directory which has been added to the binary shell path), and you are good to go. It’s pretty self explanatory.

#!/bin/sh
# git-remotebranch <action> <branch_name>
# author: Mark Shust <[email protected]>

if [ -z ${2} ]; then
  echo "You must use this script in the format git-remotebranch <action> <branch_name>"
  exit
fi

case $1 in
'add')
    git checkout -b ${2}
    git push -u origin ${2}
    echo "The ${2} remote branch has been added"
    ;;
'rm')
    git push origin :heads/${2}
    # also delete local branch, comment out if not needed
    git branch -D ${2}
    echo "The ${2} remote branch has been removed"
    ;;
'co')
    git checkout --track -b ${2} origin/${2}
    ;;
*)
    echo "Invalid action. Must be 'add', 'rm' or 'co'."
    ;;
esac

Are you a Magento geek?

Signup for my newsletter and I'll let you know about Magento-related blogs, courses & more.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK