#!/bin/bashREMOTE=$1 # Rewrite this to make it optional...BRANCH=$2# Uncomment the following line to create BRANCH locally first#git checkout -b ${BRANCH}git push ${ORIGIN} ${BRANCH}:refs/heads/${BRANCH} &&git config branch.${BRANCH}.remote ${REMOTE} &&git config branch.${BRANCH}.merge refs/heads/${BRANCH}
$ git_push_new_branch.sh
Have you run your unit tests yet? If so, pass OK or a branch name, and try again
usage: git_push_new_branch {OK|BRANCH_NAME}
e.g.
git_push_new_branch -> Displays prompt reminding you to run unit testsgit_push_new_branch OK -> Pushes the current branch as a new branch to the origingit_push_new_branch MYBRANCH -> Pushes branch MYBRANCH as a new branch to the origin
git_push_new_branch.sh
function show_help(){IT=$(cat <<EOF
Have you run your unit tests yet? If so, pass OK or a branch name, and try again
usage: git_push_new_branch {OK|BRANCH_NAME}
e.g.
git_push_new_branch.sh -> Displays prompt reminding you to run unit testsgit_push_new_branch.sh OK -> Pushes the current branch as a new branch to the origingit_push_new_branch.sh MYBRANCH -> Pushes branch MYBRANCH as a new branch to the origin
)echo "$IT"exit}
if [ -z "$1" ]thenshow_helpfi
CURR_BRANCH=$(git rev-parse --abbrev-ref HEAD)if [ "$1" == "OK" ]thenBRANCH=$CURR_BRANCHelseBRANCH=${1:-$CURR_BRANCH}fi
git push -u origin $BRANCH
#!/usr/bin/env python3
import argparseimport subprocessimport sys
def publish(args):return subprocess.run(['git', 'push', '--set-upstream', args.remote, args.branch]).returncode
def parse_args():parser = argparse.ArgumentParser(description='Push and set upstream for a branch')parser.add_argument('-r', '--remote', default='origin',help="The remote name (default is 'origin')")parser.add_argument('-b', '--branch', help='The branch name (default is whatever HEAD is pointing to)',default='HEAD')return parser.parse_args()
def main():args = parse_args()return publish(args)
if __name__ == '__main__':sys.exit(main())
然后git publish -h将向您显示使用信息:
usage: git-publish [-h] [-r REMOTE] [-b BRANCH]
Push and set upstream for a branch
optional arguments:-h, --help show this help message and exit-r REMOTE, --remote REMOTEThe remote name (default is 'origin')-b BRANCH, --branch BRANCHThe branch name (default is whatever HEAD is pointing to)