Fix pr checkout, cannot set up tracking info
#9497
Open
+6
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4287
Briefly,
gh pr checkout <pr> [--branch LOCAL_BRANCH]works in two steps:<pr>by runninggit fetch REMOTE +refs/heads/BRANCH:refs/remotes/REMOTE/BRANCHgit checkout -b LOCAL_BRANCH --track REMOTE/BRANCHWhat #4287 reported is that when the fetch
refs/remotes/REMOTE/BRANCHis not covered inremote.REMOTE.fetchgit config, then the second step failed withThis PR solves this problem by running1
if local branch
REMOTE/BRANCHdoesn't exist after the first step.Note that
remote.<name>.fetchis a multi-valued Git config, though not clearly documented.Note also that an old syntax
git config --add <name> <value>is used to gain compatibility with old Git versions. Since Git 2.26.0,git configlearnt some new subcommands and options, see the section Deprecated modes ingit configdoc.TODO
remote.origin.fetchconfig in test.Footnotes
Just realized that it does exactly the same as
git remote set-branches --add origin mybranchmentioned by @mislav in https://github.com/cli/cli/issues/4287#issuecomment-915112505 ↩