Skip to content

Commit 4f88845

Browse files
llucaxGeod24
authored andcommitted
pull: Remove the last resort default for --base
Both `pull new` and `pull attach` have a last resort `master` default for `--base` but it makes little sense, as repositories sometimes have a different default branch, or have no `master` at all. Now that GitHub have changed the default branch to `main` for new projects (and many projects are moving away from using `master` as a name for anything altogether) it makes less sense that ever to use this last resort default. Now an error will be shown if the `pull new` or `pull attach` commands have no remote tracking branch or a `hub.pullbase` configuration is present. Fixes #174.
1 parent c7950ca commit 4f88845

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

git-hub

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ class Config:
359359
self.forkrepo = self.username + '/' + upstream[1]
360360
self.upstreamremote = git_config('upstreamremote', 'upstream')
361361
self.forkremote = git_config('forkremote', 'fork')
362-
self.pullbase = git_config('pullbase', 'master')
363362
self.urltype = git_config('urltype', 'ssh_url')
364363
self.baseurl = self.sanitize_url('baseurl',
365364
git_config('baseurl', 'https://api.github.com'))
@@ -1423,7 +1422,13 @@ class PullUtil (IssueUtil):
14231422
die("Can't guess remote branch name, please "
14241423
"use --create-branch to specify one")
14251424
base = args.base or cls.tracking_branch(head_name) or \
1426-
config.pullbase
1425+
git_config('pullbase')
1426+
if base is None:
1427+
die('No base branch specified, you have to either use --base, have '
1428+
'a tracking branch configured for the current branch or '
1429+
'configure a default using `git config hub.pullbase` (to '
1430+
're-enable the old global `master` default, use `git '
1431+
'config --global hub.pullbase master`)')
14271432
gh_head = config.forkrepo.split('/')[0] + ':' + remote_head
14281433
return head_ref, head_name, remote_head, base, gh_head
14291434

@@ -1495,7 +1500,7 @@ class PullCmd (IssueCmd):
14951500
help="branch (or git ref) you want your "
14961501
"changes pulled into (uses the tracking "
14971502
"branch by default, or hub.pullbase if "
1498-
"there is none, or 'master' as a fallback)")
1503+
"there is none)")
14991504
parser.add_argument('-c', '--create-branch',
15001505
metavar='NAME',
15011506
help="create a new remote branch with NAME "

man.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ __ https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-gith
330330
Branch (or git ref) you want your changes pulled into. By default the
331331
tracking branch (`branch.<ref>.merge` configuration variable) is used or
332332
the configuration `hub.pullbase` if not tracking a remote branch. If none
333-
is present, it defaults to **master**. The repository to use as the base
334-
is taken from the `hub.upstream` configuration.
333+
is present an error will be displayed.
335334

336335
\-c NAME, --create-branch=NAME
337336
Create a new remote branch with (with name **NAME**) as the real head for
@@ -367,11 +366,7 @@ __ https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-gith
367366
first commit message is used as with the `new` subcommand.
368367

369368
\-b BASE, --base=BASE
370-
Base branch to which issue the pull request. If this option is not
371-
present, then the base branch is taken from the configuration
372-
`hub.pullbase` (or just **master** if that configuration is not present
373-
either). The repository to use as the base is taken from the
374-
`hub.upstream` configuration.
369+
Same as `pull new`, please see the details there.
375370

376371
\-c NAME, --create-branch=NAME
377372
Create a new remote branch with (with name **NAME**) as the real head for
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### No last resort default for `pull new`/`attach --base`
2+
3+
The old `master` default made little sense, as repositories sometimes have
4+
a different default branch, or have no `master` at all. Now that GitHub have
5+
changed the default branch to `main` for new projects (and many projects are
6+
moving away from using `master` as a name for anything altogether) it makes
7+
less sense that ever to use this last resort default.
8+
9+
An error will be shown if the `pull new` or `pull attach` commands have no
10+
remote tracking branch or a `hub.pullbase` configuration is present. If you
11+
relied on this behaviour just do: `git config hub.pullbase master` (add
12+
`--global` to set this default globally for all your repos).

0 commit comments

Comments
 (0)