Untuk fleksibilitas terbaik, Anda bisa menggunakan perintah custom Git . Misalnya, buat skrip Python berikut di suatu tempat di $PATH
bawah nama Anda git-publish
dan buat agar dapat dieksekusi:
#!/usr/bin/env python3
import argparse
import subprocess
import 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())
Maka git publish -h
akan muncul informasi penggunaan:
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 REMOTE
The remote name (default is 'origin')
-b BRANCH, --branch BRANCH
The branch name (default is whatever HEAD is pointing to)