snippetjavascriptTip
Set the default push branch name in Git
Viewed 0 times
defaultsetgitthenamebranchpush
Problem
Manually specifying the remote branch name when pushing can be a hassle. Git provides a way to automate this process by setting the default push branch name to the current branch name.
Using
Using the
Using
git config push.default current will configure Git to use the name of the current branch as the default remote branch name. This setting is particularly useful when local branches are expected to have the same name as their remote counterparts.Using the
--global flag will set this configuration globally on your machine.Solution
# Syntax: git config [--global] push.default current
git config --global push.default current
git checkout -b my-branch
git push -u
# Pushes to origin/my-branchUsing the
--global flag will set this configuration globally on your machine.Code Snippets
# Syntax: git config [--global] push.default current
git config --global push.default current
git checkout -b my-branch
git push -u
# Pushes to origin/my-branchContext
From 30-seconds-of-code: set-default-push-branch
Revisions (0)
No revisions yet.