HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptTip

Automate Git upstream branch creation

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
upstreamgitcreationbranchautomate

Problem

Manually creating upstream branches on push can be a tedious task. Luckily, Git provides a way to automate this process. You can use git config to enable automatic upstream branch creation on push:
Using push.autoSetupRemote will automatically create a new branch on the remote repository, if it doesn't exist. Workflows that benefit most from this setup are ones where local branches are expected to have the same name as their remote counterparts. You can use the --global flag to enable this setting globally on your machine.

Solution

# Syntax: git config [--global] --add --bool push.autoSetupRemote true

git config --global --add --bool push.autoSetupRemote true
# `git push` will automatically create new branches, if they don't exist

git checkout -b my-branch
git push
# Pushes to origin/my-branch

Code Snippets

# Syntax: git config [--global] --add --bool push.autoSetupRemote true

git config --global --add --bool push.autoSetupRemote true
# `git push` will automatically create new branches, if they don't exist

git checkout -b my-branch
git push
# Pushes to origin/my-branch

Context

From 30-seconds-of-code: automatic-push-upstream

Revisions (0)

No revisions yet.