Repository: VirtusLab/git-machete

Issue:
Remote incorrectly assigned for a newly-checked-out parent branch in `github checkout-prs`
Here's the full log:

<details>
<summary>Log of github checkout-prs</summary>
<pre>
➜ 18:42 ~/git-machete develop $ git machete s -l
  master  v3.4.1
  │ 
  │ Issue #233: Provide support for 4th location of GitHub token. (#266)
  │ Issue #169: Enforce that fork-point options values have to be ancestors of branch. (#263)
  │ [Blocked by release v3.4.0] Run `git fetch --prune` in all contexts (#267)
  │ Merge branch 'develop' into backport/v3.4.1
  │ Issue #218: Update the badge link. (#274)
  │ Issues #163 and #117: Organise constants of similar context into structures. (#283)
  │ Issue #245: Fix git machete show current, so it doesn't run git symbolic-ref twice. (#282)
  │ Issue #161: Decouple MacheteClient and GitContext from CommandLineOptions class. (#281)
  │ Issue #275 : Restore dry run snap builds in develop/hotfix branches (#280)
  │ Move `validate_python_version` to `git-machete` file (#296)
  │ Issue #284: Fix the issue that bash completion scripts completes local paths for commands if no matching prefix has been found. (#298)
  │ updated contributing.md (#301)
  └─develop  v3.5.0
➜ 18:42 ~/git-machete develop $ git machete github checkout-prs 300
Fetching kgadek...
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 61 (delta 41), reused 59 (delta 41), pack-reused 0
Unpacking objects: 100% (61/61), 11.59 KiB | 989.00 KiB/s, done.
From https://github.com/kgadek/git-machete
 * [new branch]      bugfix/completion                -> kgadek/bugfix/completion
 * [new branch]      bugfix/restore_snaps             -> kgadek/bugfix/restore_snaps
 * [new branch]      develop                          -> kgadek/develop
 * [new branch]      feature/go-back                  -> kgadek/feature/go-back
 * [new branch]      feature/manage-remote-branches   -> kgadek/feature/manage-remote-branches
 * [new branch]      improve/exit                     -> kgadek/improve/exit
 * [new branch]      improve/infer-remote-head        -> kgadek/improve/infer-remote-head
 * [new branch]      improve/soft-remote-head         -> kgadek/improve/soft-remote-head
 * [new branch]      issue/290-fish-completion        -> kgadek/issue/290-fish-completion
 * [new branch]      master                           -> kgadek/master
 * [new branch]      refactor/distinguish_str_in_mypy -> kgadek/refactor/distinguish_str_in_mypy
 * [new branch]      remove/go-branch                 -> kgadek/remove/go-branch
A local branch issue/290-fish-completion does not exist, but a remote branch kgadek/issue/290-fish-completion exists.
Checking out issue/290-fish-completion locally...
Branch 'issue/290-fish-completion' set up to track remote branch 'issue/290-fish-completion' from 'kgadek'.
Switched to a new branch 'issue/290-fish-completion'
Added branch issue/290-fish-completion onto develop
Annotating issue/290-fish-completion as PR #300 (kgadek)
Pull request #300 checked out at local branch issue/290-fish-completion
➜ 18:43 ~/git-machete issue/290-fish-completion PR #300 (kgadek) $ git machete s -l
  master  v3.4.1
  │ 
  │ Issue #233: Provide support for 4th location of GitHub token. (#266)
  │ Issue #169: Enforce that fork-point options values have to be ancestors of branch. (#263)
  │ [Blocked by release v3.4.0] Run `git fetch --prune` in all contexts (#267)
  │ Merge branch 'develop' into backport/v3.4.1
  │ Issue #218: Update the badge link. (#274)
  │ Issues #163 and #117: Organise constants of similar context into structures. (#283)
  │ Issue #245: Fix git machete show current, so it doesn't run git symbolic-ref twice. (#282)
  │ Issue #161: Decouple MacheteClient and GitContext from CommandLineOptions class. (#281)
  │ Issue #275 : Restore dry run snap builds in develop/hotfix branches (#280)
  │ Move `validate_python_version` to `git-machete` file (#296)
  │ Issue #284: Fix the issue that bash completion scripts completes local paths for commands if no matching prefix has been found. (#298)
  │ updated contributing.md (#301)
  └─develop  v3.5.0
    │ 
    │ Issue #284: Fix the issue that bash completion scripts completes local paths for commands if no matching prefix has been found. (#298)
    │ Provide fish shell completions
    │ fish completion: docs [TODOs]
    │ fish completion: completions for some of the commands
    │ fish completion: suppress file completion for entirety of 'git machete'
    │ fish completion: whitespace
    │ fish completion: todos targetted at PR/wip
    │ fish completion: install fish for CircleCI
    │ fish completion: add release note
    │ fish completion: all of the commands
    └─issue/290-fish-completion  PR #300 (kgadek)  v3.5.0
➜ 18:43 ~/git-machete issue/290-fish-completion PR #300 (kgadek) $ git machete github checkout-prs 303
A local branch improve/exit does not exist. Creating out of develop
Switched to a new branch 'improve/exit'
Added branch improve/exit onto develop
A local branch fix/help_outside_repo does not exist, but a remote branch origin/fix/help_outside_repo exists.
Checking out fix/help_outside_repo locally...
Branch 'fix/help_outside_repo' set up to track remote branch 'fix/help_outside_repo' from 'origin'.
Switched to a new branch 'fix/help_outside_repo'
Added branch fix/help_outside_repo onto improve/exit
Annotating fix/help_outside_repo as PR #303 (BartoszSiwinski)
Annotating improve/exit as PR #287 (BartoszSiwinski)
Pull request #303 checked out at local branch fix/help_outside_repo
➜ 18:43 ~/git-machete fix/help_outside_repo PR #303 (BartoszSiwinski) $ git machete s -l
  master  v3.4.1
  │ 
  │ Issue #233: Provide support for 4th location of GitHub token. (#266)
  │ Issue #169: Enforce that fork-point options values have to be ancestors of branch. (#263)
  │ [Blocked by release v3.4.0] Run `git fetch --prune` in all contexts (#267)
  │ Merge branch 'develop' into backport/v3.4.1
  │ Issue #218: Update the badge link. (#274)
  │ Issues #163 and #117: Organise constants of similar context into structures. (#283)
  │ Issue #245: Fix git machete show current, so it doesn't run git symbolic-ref twice. (#282)
  │ Issue #161: Decouple MacheteClient and GitContext from CommandLineOptions class. (#281)
  │ Issue #275 : Restore dry run snap builds in develop/hotfix branches (#280)
  │ Move `validate_python_version` to `git-machete` file (#296)
  │ Issue #284: Fix the issue that bash completion scripts completes local paths for commands if no matching prefix has been found. (#298)
  │ updated contributing.md (#301)
  └─develop  v3.5.0
    │ 
    │ Issue #284: Fix the issue that bash completion scripts completes local paths for commands if no matching prefix has been found. (#298)
    │ Provide fish shell completions
    │ fish completion: docs [TODOs]
    │ fish completion: completions for some of the commands
    │ fish completion: suppress file completion for entirety of 'git machete'
    │ fish completion: whitespace
    │ fish completion: todos targetted at PR/wip
    │ fish completion: install fish for CircleCI
    │ fish completion: add release note
    │ fish completion: all of the commands
    └─issue/290-fish-completion  PR #300 (kgadek)  v3.5.0
    │ 
    └─improve/exit  PR #287 (BartoszSiwinski) (diverged from kgadek)  v3.5.0
      │ 
      │ Issue #265: Create exit_script method that will process script exiting.
      │ Fix mypy issue.
      │ Replace MacheteException msg with 'Aborting.'.
      │ Add comment explaining why it's useful to have exit_script method.
      │ Update hooks description.
      │ Update hooks description.
      │ Merge branch 'develop' into improve/exit
      │ Issue #289: Add github command to top-level help.
      │ Issue #299: Make help command and --help option work outside of a git repository.
      │ Fix test_help method and correct exit code for --help Action of Parser.
      │ Simplify further logic.
      │ Revert "Issue #289: Add github command to top-level help."
      └─fix/help_outside_repo  PR #303 (BartoszSiwinski)  v3.5.0
➜ 18:43 ~/git-machete fix/help_outside_repo PR #303 (BartoszSiwinski) $ git status
On branch fix/help_outside_repo
Your branch is up to date with 'origin/fix/help_outside_repo'.

nothing to commit, working tree clean
</pre>
</details>

The problem is that for PR #287, `kgadek`'s fork (rather than this very repo) has been selected as remote (or actually, probably no remote has been assigned &mdash; `kgadek` is only inferred by git-machete based on branch naming, and **not** on tracking data in `git config`). For PR #303 the `origin` remote is correctly selected, tho.

<details>
<summary>git config -l</summary>
<pre>
user.name=Pawel Lipski
user.email=pawel.p.lipski@gmail.com
core.autocrlf=input
color.ui=auto
alias.cam=commit -am
alias.co=checkout
alias.l=log
alias.s=status
push.default=current
advice.macheteeditorselection=false
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:VirtusLab/git-machete.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
advice.ignoredhook=true
travis.slug=VirtusLab/git-machete
status.showuntrackedfiles=normal
status.relativepaths=false
branch.feature/types.remote=origin
branch.feature/types.merge=refs/heads/feature/types
branch.improve/traverse-reset-hard.remote=origin
branch.improve/traverse-reset-hard.merge=refs/heads/improve/traverse-reset-hard
branch.chore/annotated-tags.remote=origin
branch.chore/annotated-tags.merge=refs/heads/chore/annotated-tags
branch.orphan/brew-package-check.remote=origin
branch.orphan/brew-package-check.merge=refs/heads/orphan/brew-package-check
branch.chore/nixpkgs.remote=origin
branch.chore/nixpkgs.merge=refs/heads/chore/nixpkgs
branch.chore/ci-snap-publish.remote=origin
branch.chore/ci-snap-publish.merge=refs/heads/chore/ci-snap-publish
branch.fix/ci-minor.remote=origin
branch.fix/ci-minor.merge=refs/heads/fix/ci-minor
branch.chore/snap-classic.remote=origin
branch.chore/snap-classic.merge=refs/heads/chore/snap-classic
branch.fix/rpm-python-pip.remote=origin
branch.fix/rpm-python-pip.merge=refs/heads/fix/rpm-python-pip
branch.fix/nix-no-reviewer.remote=origin
branch.fix/nix-no-reviewer.merge=refs/heads/fix/nix-no-reviewer
branch.chore/move-docker-images.remote=origin
branch.chore/move-docker-images.merge=refs/heads/chore/move-docker-images
machete.overrideForkPoint.develop.to=e60e78216f587d6b4f08cb548f7ef6df3d5f9653
machete.overrideForkPoint.develop.whiledescendantof=8aefe5c363ce07f64afdd6b51a2ab59df791bb67
branch.improve/editor-choice.remote=origin
branch.improve/editor-choice.merge=refs/heads/improve/editor-choice
branch.fix/logging.remote=origin
branch.fix/logging.merge=refs/heads/fix/logging
branch.feature/cli-minor.remote=origin
branch.feature/cli-minor.merge=refs/heads/feature/cli-minor
branch.improve/help-fmt.remote=origin
branch.improve/help-fmt.merge=refs/heads/improve/help-fmt
branch.improve/prompt-ynq.remote=origin
branch.improve/prompt-ynq.merge=refs/heads/improve/prompt-ynq
branch.docs/asciinema-gif.remote=origin
branch.docs/asciinema-gif.merge=refs/heads/docs/asciinema-gif
branch.feature/add-from-remote.remote=origin
branch.feature/add-from-remote.merge=refs/heads/feature/add-from-remote
branch.feature/post-slide-out-hook.remote=origin
branch.feature/post-slide-out-hook.merge=refs/heads/feature/post-slide-out-hook
branch.feature/advance.remote=origin
branch.feature/advance.merge=refs/heads/feature/advance
branch.bugfix/cwd-missing.remote=origin
branch.bugfix/cwd-missing.merge=refs/heads/bugfix/cwd-missing
branch.chore/deploy-on-master.remote=origin
branch.chore/deploy-on-master.merge=refs/heads/chore/deploy-on-master
branch.foo.remote=origin
branch.foo.merge=refs/heads/foo
branch.chore/editor-vars.remote=origin
branch.chore/editor-vars.merge=refs/heads/chore/editor-vars
branch.improve/fork-point-minor.remote=origin
branch.improve/fork-point-minor.merge=refs/heads/improve/fork-point-minor
branch.feature/manage-remote-branches.remote=origin
branch.feature/manage-remote-branches.merge=refs/heads/feature/manage-remote-branches
branch.bugfix/show-root.remote=origin
branch.bugfix/show-root.merge=refs/heads/bugfix/show-root
branch.improve/error-warn-fmt.remote=origin
branch.improve/error-warn-fmt.merge=refs/heads/improve/error-warn-fmt
branch.feature/go-back.remote=origin
branch.feature/go-back.merge=refs/heads/feature/go-back
branch.improve/discover-skip-merged.remote=origin
branch.improve/discover-skip-merged.merge=refs/heads/improve/discover-skip-merged
branch.refactor/slide-out.remote=origin
branch.refactor/slide-out.merge=refs/heads/refactor/slide-out
branch.chore/tox-rectify.remote=origin
branch.chore/tox-rectify.merge=refs/heads/chore/tox-rectify
branch.optimize/anno-show-no-verify-branches.remote=origin
branch.optimize/anno-show-no-verify-branches.merge=refs/heads/optimize/anno-show-no-verify-branches
branch.bugfix/links-405.remote=origin
branch.bugfix/links-405.merge=refs/heads/bugfix/links-405
branch.chore/focal.remote=origin
branch.chore/focal.merge=refs/heads/chore/focal
branch.improve/soft-remote-head.remote=origin
branch.improve/soft-remote-head.merge=refs/heads/improve/soft-remote-head
branch.bugfix/advance-missing-post-slide-out.remote=origin
branch.bugfix/advance-missing-post-slide-out.merge=refs/heads/bugfix/advance-missing-post-slide-out
machete.overrideForkPoint.feature/go-back.to=73021bc11a37c530a892cbea1bd25d6f986b0c21
machete.overrideForkPoint.feature/go-back.whiledescendantof=ec2411e9ca5e3c5984aad397aa0874b00a427f48
branch.improve/infer-remote-head.remote=origin
branch.improve/infer-remote-head.merge=refs/heads/improve/infer-remote-head
branch.remove/go-branch.remote=origin
branch.remove/go-branch.merge=refs/heads/remove/go-branch
branch.doc/readme-first-5-mins.remote=origin
branch.doc/readme-first-5-mins.merge=refs/heads/doc/readme-first-5-mins
branch.feature/slide-out-invalid-branches.remote=origin
branch.feature/slide-out-invalid-branches.merge=refs/heads/feature/slide-out-invalid-branches
branch.TEMP/doc/readme-first-5-mins.remote=origin
branch.TEMP/doc/readme-first-5-mins.merge=refs/heads/TEMP/doc/readme-first-5-mins
branch.improve/discover-develop-root.remote=origin
branch.improve/discover-develop-root.merge=refs/heads/improve/improve/discover-develop-root
branch.chore/discover-main.remote=origin
branch.chore/discover-main.merge=refs/heads/chore/discover-main
branch.fix/logs.remote=origin
branch.fix/logs.merge=refs/heads/fix/logs
branch.chore/travis-links.remote=origin
branch.chore/travis-links.merge=refs/heads/chore/travis-links
branch.improve/discover-develop-as-root.remote=origin
branch.improve/discover-develop-as-root.merge=refs/heads/improve/discover-develop-as-root
branch.feature/squash.remote=origin
branch.feature/squash.merge=refs/heads/feature/squash
branch.bugfix/gmip-681-discover-fp-logic.remote=origin
branch.bugfix/gmip-681-discover-fp-logic.merge=refs/heads/bugfix/gmip-681-discover-fp-logic
branch.improve/squash-keep-author.remote=origin
branch.improve/squash-keep-author.merge=refs/heads/improve/squash-keep-author
branch.chore/check-python.remote=origin
branch.chore/check-python.merge=refs/heads/chore/check-python
branch.circleci-project-setup.remote=origin
branch.circleci-project-setup.merge=refs/heads/circleci-project-setup
branch.chore/nixpkgs-dry-run-shallow-fetch.remote=origin
branch.chore/nixpkgs-dry-run-shallow-fetch.merge=refs/heads/chore/nixpkgs-dry-run-shallow-fetch
branch.chore/remove-travis.remote=origin
branch.chore/remove-travis.merge=refs/heads/chore/remove-travis
branch.feature/anno-github-prs.remote=origin
branch.feature/anno-github-prs.merge=refs/heads/feature/anno-github-prs
branch.bugfix/sync-github-prs.remote=origin
branch.bugfix/sync-github-prs.merge=refs/heads/bugfix/sync-github-prs
branch.chore/misc-msgs.remote=origin
branch.chore/misc-msgs.merge=refs/heads/chore/misc-msgs
branch.feature/hub.remote=origin
branch.feature/hub.merge=refs/heads/feature/hub
branch.bugfix/add-crash.remote=origin
branch.bugfix/add-crash.merge=refs/heads/bugfix/add-crash
branch.bugfix/nixos-version.remote=origin
branch.bugfix/nixos-version.merge=refs/heads/bugfix/nixos-version
remote.asford.url=git@github.com:asford/git-machete.git
remote.asford.fetch=+refs/heads/*:refs/remotes/asford/*
branch.refactor/machete-context.remote=origin
branch.refactor/machete-context.merge=refs/heads/refactor/machete-context
branch.bugfix/no-op-rebase-in-fork-point.remote=origin
branch.bugfix/no-op-rebase-in-fork-point.merge=refs/heads/bugfix/no-op-rebase-in-fork-point
branch.optimize/detect-squash-caching.remote=origin
branch.optimize/detect-squash-caching.merge=refs/heads/optimize/detect-squash-caching
branch.chore/minor-fixes.remote=origin
branch.chore/minor-fixes.merge=refs/heads/chore/minor-fixes
branch.bugfix/help-crashing.remote=origin
branch.bugfix/help-crashing.merge=refs/heads/bugfix/help-crashing
branch.bugfix/update-nixpkgs-contributing-url.remote=origin
branch.bugfix/update-nixpkgs-contributing-url.merge=refs/heads/bugfix/update-nixpkgs-contributing-url
branch.show_target.remote=origin
branch.show_target.merge=refs/heads/show_target
branch.no_push.remote=origin
branch.no_push.merge=refs/heads/no_push
branch.chore/reindent-completion.remote=origin
branch.chore/reindent-completion.merge=refs/heads/chore/reindent-completion
branch.chore/shields.remote=origin
branch.chore/shields.merge=refs/heads/chore/shields
branch.bugfix/nixos-not-executable.remote=origin
branch.bugfix/nixos-not-executable.merge=refs/heads/bugfix/nixos-not-executable
branch.chore/remove-nixpkgs-release.remote=origin
branch.chore/remove-nixpkgs-release.merge=refs/heads/chore/remove-nixpkgs-release
branch.refactor/utils.remote=origin
branch.refactor/utils.merge=refs/heads/refactor/utils
branch.bugfix/show-help.remote=origin
branch.bugfix/show-help.merge=refs/heads/bugfix/show-help
branch.improve/ensure_version_bumped.remote=origin
branch.improve/ensure_version_bumped.merge=refs/heads/improve/ensure_version_bumped
branch.basi_functional_tests.remote=origin
branch.basi_functional_tests.merge=refs/heads/basi_functional_tests
branch.basi_temp_branch.remote=origin
branch.basi_temp_branch.merge=refs/heads/basi_temp_branch
branch.improve/coverage_reporting.remote=origin
branch.improve/coverage_reporting.merge=refs/heads/improve/coverage_reporting
branch.improve/method_names.remote=git@github.com:garg-tanishka/git-machete.git
branch.improve/method_names.merge=refs/heads/improve/method_names
branch.bugfix/createpr_options.remote=origin
branch.bugfix/createpr_options.merge=refs/heads/bugfix/createpr_options
machete.slideOut.deletelocalbranch=true
branch.bugfix/token-from-env-regression.remote=origin
branch.bugfix/token-from-env-regression.merge=refs/heads/bugfix/token-from-env-regression
branch.issue162.remote=git@github.com:mohitsaxenaknoldus/git-machete.git
branch.issue162.merge=refs/heads/issue162
branch.testing/github_methods.remote=origin
branch.testing/github_methods.merge=refs/heads/testing/github_methods
branch.testing/retarget-pr-unshare-mock-state.remote=origin
branch.testing/retarget-pr-unshare-mock-state.merge=refs/heads/testing/retarget-pr-unshare-mock-state
branch.improve/parser.remote=origin
branch.improve/parser.merge=refs/heads/improve/parser
branch.bugfix/remove-n-option.remote=origin
branch.bugfix/remove-n-option.merge=refs/heads/bugfix/remove-n-option
remote.mohitsaxenaknoldus.url=https://github.com/mohitsaxenaknoldus/git-machete
remote.mohitsaxenaknoldus.fetch=+refs/heads/*:refs/remotes/mohitsaxenaknoldus/*
remote.garg-tanishka.url=https://github.com/garg-tanishka/git-machete
remote.garg-tanishka.fetch=+refs/heads/*:refs/remotes/garg-tanishka/*
branch.develop.remote=origin
branch.develop.merge=refs/heads/develop
branch.hotfix/snap-logo-path.remote=origin
branch.hotfix/snap-logo-path.merge=refs/heads/hotfix/snap-logo-path
machete.overrideForkPoint.master.to=e60e78216f587d6b4f08cb548f7ef6df3d5f9653
machete.overrideForkPoint.master.whiledescendantof=758f20230c15d5451ab645db015676a5e811ed07
machete.overrideForkPoint.backport/v3.4.1.to=e60e78216f587d6b4f08cb548f7ef6df3d5f9653
machete.overrideForkPoint.backport/v3.4.1.whiledescendantof=758f20230c15d5451ab645db015676a5e811ed07
branch.backport/v3.4.1.remote=origin
branch.backport/v3.4.1.merge=refs/heads/backport/v3.4.1
branch.refactor/distinguish_str_in_mypy.remote=origin
branch.refactor/distinguish_str_in_mypy.merge=refs/heads/refactor/distinguish_str_in_mypy
remote.kgadek.url=https://github.com/kgadek/git-machete
remote.kgadek.fetch=+refs/heads/*:refs/remotes/kgadek/*
branch.issue/290-fish-completion.remote=kgadek
branch.issue/290-fish-completion.merge=refs/heads/issue/290-fish-completion
branch.fix/help_outside_repo.remote=origin
branch.fix/help_outside_repo.merge=refs/heads/fix/help_outside_repo
</pre>
</details>

<details>
<summary>git remote -v</summary>
<pre>
asford	git@github.com:asford/git-machete.git (fetch)
asford	git@github.com:asford/git-machete.git (push)
garg-tanishka	https://github.com/garg-tanishka/git-machete (fetch)
garg-tanishka	https://github.com/garg-tanishka/git-machete (push)
kgadek	https://github.com/kgadek/git-machete (fetch)
kgadek	https://github.com/kgadek/git-machete (push)
mohitsaxenaknoldus	https://github.com/mohitsaxenaknoldus/git-machete (fetch)
mohitsaxenaknoldus	https://github.com/mohitsaxenaknoldus/git-machete (push)
origin	git@github.com:VirtusLab/git-machete.git (fetch)
origin	git@github.com:VirtusLab/git-machete.git (push)
</pre>
</details>

<details>
<summary>git branch -a</summary>
<pre>
  TEMP/doc/readme-first-5-mins
  backport/v3.4.1
  bar
  basi_functional_tests
  basi_temp_branch
  bugfix/add-crash
  bugfix/advance-missing-post-slide-out
  bugfix/createpr_options
  bugfix/cwd-missing
  bugfix/gmip-681-discover-fp-logic
  bugfix/help-crashing
  bugfix/links-405
  bugfix/nixos-not-executable
  bugfix/nixos-version
  bugfix/no-op-rebase-in-fork-point
  bugfix/remove-n-option
  bugfix/show-help
  bugfix/show-root
  bugfix/sync-github-prs
  bugfix/token-from-env-regression
  bugfix/update-nixpkgs-contributing-url
  chore/annotated-tags
  chore/check-python
  chore/ci-snap-publish
  chore/deploy-on-master
  chore/discover-main
  chore/editor-vars
  chore/focal
  chore/minor-fixes
  chore/misc-msgs
  chore/move-docker-images
  chore/nixpkgs
  chore/nixpkgs-dry-run-shallow-fetch
  chore/reindent-completion
  chore/remove-nixpkgs-release
  chore/remove-travis
  chore/shields
  chore/snap-classic
  chore/sphinx-docs
  chore/tox-rectify
  chore/travis-links
  circleci-project-setup
  develop
  develop2
  doc/readme-first-5-mins
  docs/asciinema-gif
  feature/add-from-remote
  feature/add-mypy-env-to-tox
  feature/advance
  feature/anno-github-prs
  feature/cli-minor
  feature/delete-on-slide-out
  feature/go-back
  feature/hub
  feature/manage-remote-branches
  feature/post-slide-out-hook
  feature/slide-out-invalid-branches
  feature/squash
  feature/types
  fix/ci-minor
  fix/help_outside_repo
  fix/logging
  fix/logs
  fix/nix-no-reviewer
  fix/rpm-python-pip
  foo
  foo-bar-bar
  foobarquz
  hotfix/snap-logo-path
  improve/coverage_reporting
  improve/discover-develop-as-root
  improve/discover-develop-root
  improve/discover-skip-merged
  improve/editor-choice
  improve/ensure_version_bumped
  improve/error-warn-fmt
* improve/exit
  improve/fork-point-minor
  improve/help-fmt
  improve/infer-remote-head
  improve/method_names
  improve/parser
  improve/prompt-ynq
  improve/soft-remote-head
  improve/squash-keep-author
  improve/traverse-reset-hard
  issue/290-fish-completion
  issue162
  master
  no_push
  optimize/anno-show-no-verify-branches
  optimize/detect-squash-caching
  orphan/brew-package-check
  refactor/distinguish_str_in_mypy
  refactor/machete-context
  refactor/slide-out
  refactor/utils
  remove/go-branch
  show_target
  testing/github_methods
  testing/retarget-pr-unshare-mock-state
  remotes/asford/auth_token
  remotes/asford/bugfix/add-crash
  remotes/asford/bugfix/gmip-681-discover-fp-logic
  remotes/asford/bugfix/nixos-version
  remotes/asford/bugfix/sync-github-prs
  remotes/asford/chore/check-python
  remotes/asford/chore/misc-msgs
  remotes/asford/chore/nixpkgs-dry-run-shallow-fetch
  remotes/asford/chore/remove-travis
  remotes/asford/chore/travis-links
  remotes/asford/chore/v3
  remotes/asford/circleci-project-setup
  remotes/asford/detect_squash
  remotes/asford/detect_squash_tree
  remotes/asford/develop
  remotes/asford/feature/go-back
  remotes/asford/feature/hub
  remotes/asford/feature/manage-remote-branches
  remotes/asford/feature/types
  remotes/asford/improve/discover-develop-as-root
  remotes/asford/improve/infer-remote-head
  remotes/asford/improve/soft-remote-head
  remotes/asford/master
  remotes/asford/no_push
  remotes/asford/refactor/machete-context
  remotes/asford/remove/go-branch
  remotes/asford/show_target
  remotes/asford/slide_out_multiple
  remotes/garg-tanishka/bugfix/nixos-not-executable
  remotes/garg-tanishka/bugfix/show-help
  remotes/garg-tanishka/chore/remove-nixpkgs-release
  remotes/garg-tanishka/chore/shields
  remotes/garg-tanishka/develop
  remotes/garg-tanishka/feature/go-back
  remotes/garg-tanishka/feature/hub
  remotes/garg-tanishka/feature/manage-remote-branches
  remotes/garg-tanishka/improve/coverage_reporting
  remotes/garg-tanishka/improve/infer-remote-head
  remotes/garg-tanishka/improve/method_names
  remotes/garg-tanishka/improve/method_naming
  remotes/garg-tanishka/improve/soft-remote-head
  remotes/garg-tanishka/master
  remotes/garg-tanishka/remove/go-branch
  remotes/garg-tanishka/remove/spam-displayed
  remotes/kgadek/bugfix/completion
  remotes/kgadek/bugfix/restore_snaps
  remotes/kgadek/develop
  remotes/kgadek/feature/go-back
  remotes/kgadek/feature/manage-remote-branches
  remotes/kgadek/improve/exit
  remotes/kgadek/improve/infer-remote-head
  remotes/kgadek/improve/soft-remote-head
  remotes/kgadek/issue/290-fish-completion
  remotes/kgadek/master
  remotes/kgadek/refactor/distinguish_str_in_mypy
  remotes/kgadek/remove/go-branch
  remotes/mohitsaxenaknoldus/black_example
  remotes/mohitsaxenaknoldus/develop
  remotes/mohitsaxenaknoldus/docs/read_the_docs
  remotes/mohitsaxenaknoldus/enchance/checkout-pr
  remotes/mohitsaxenaknoldus/feature/go-back
  remotes/mohitsaxenaknoldus/feature/manage-remote-branches
  remotes/mohitsaxenaknoldus/improve/infer-remote-head
  remotes/mohitsaxenaknoldus/improve/soft-remote-head
  remotes/mohitsaxenaknoldus/issue173
  remotes/mohitsaxenaknoldus/master
  remotes/mohitsaxenaknoldus/remove/go-branch
  remotes/origin/bugfix/completion
  remotes/origin/bugfix/create-pr-diverged
  remotes/origin/bugfix/restore_snaps
  remotes/origin/build/tar-ignore
  remotes/origin/develop
  remotes/origin/feature/go-back
  remotes/origin/feature/manage-remote-branches
  remotes/origin/fix/help
  remotes/origin/fix/help_outside_repo
  remotes/origin/improve/exit
  remotes/origin/improve/infer-remote-head
  remotes/origin/improve/soft-remote-head
  remotes/origin/master
  remotes/origin/refactor/distinguish_str_in_mypy
  remotes/origin/remove/go-branch
  remotes/origin/test/py10
  remotes/origin/test_branch
</pre>
</details>

I can provide the entire repo state if needed.

Discussion:

Patch:
diff --git a/git_machete/client.py b/git_machete/client.py
index 2648556..cd389c1 100644
--- a/git_machete/client.py
+++ b/git_machete/client.py
@@ -1847,6 +1847,8 @@ class MacheteClient:
         remote, (org, repo) = self.__derive_remote_and_github_org_and_repo()
         current_user: Optional[str] = git_machete.github.derive_current_user_login()
         debug('checkout_github_pr()', f'organization is {org}, repository is {repo}')
+        print(f"Fetching {remote}...")
+        self.__git.fetch_remote(remote)
 
         pr = get_pull_request_by_number_or_none(pr_no, org, repo)
         if not pr:
@@ -1861,8 +1863,9 @@ class MacheteClient:
                     remote_to_fetch: str = remote_from_pr
                 else:
                     remote_to_fetch = remote_already_added
-                print(f"Fetching {remote_to_fetch}...")
-                self.__git.fetch_remote(remote_to_fetch)
+                if remote != remote_to_fetch:
+                    print(f"Fetching {remote_to_fetch}...")
+                    self.__git.fetch_remote(remote_to_fetch)
                 if '/'.join([remote_to_fetch, pr.head]) not in self.__git.get_remote_branches():
                     raise MacheteException(f"Could not check out PR #{pr_no} because its head branch `{pr.head}` is already deleted from `{remote_to_fetch}`.")
         else:


Test patch:
diff --git a/git_machete/tests/functional/test_machete.py b/git_machete/tests/functional/test_machete.py
index 408c91f..e6f934d 100644
--- a/git_machete/tests/functional/test_machete.py
+++ b/git_machete/tests/functional/test_machete.py
@@ -2303,7 +2303,8 @@ class MacheteTester(unittest.TestCase):
          )
         os.chdir(self.repo_sandbox.local_path)
 
-        expected_msg = ("Fetching testing...\n"
+        expected_msg = ("Fetching origin...\n"
+                        "Fetching testing...\n"
                         "Warn: Pull request #5 is already closed.\n"
                         "A local branch `bugfix/remove-n-option` does not exist, but a remote branch `testing/bugfix/remove-n-option` exists.\n"
                         "Checking out `bugfix/remove-n-option` locally...\n"
@@ -2376,7 +2377,8 @@ class MacheteTester(unittest.TestCase):
         )
         os.chdir(self.repo_sandbox.local_path)
         self.rewrite_definition_file("master")
-        expected_msg = ("A local branch `chore/sync_to_docs` does not exist, but a remote branch `origin/chore/sync_to_docs` exists.\n"
+        expected_msg = ("Fetching origin...\n"
+                        "A local branch `chore/sync_to_docs` does not exist, but a remote branch `origin/chore/sync_to_docs` exists.\n"
                         "Checking out `chore/sync_to_docs` locally...\n"
                         "Added branch `chore/sync_to_docs` as a new root\n"
                         "A local branch `improve/refactor` does not exist, but a remote branch `origin/improve/refactor` exists.\n"
@@ -2407,7 +2409,8 @@ class MacheteTester(unittest.TestCase):
 
         # Check against closed pull request
         self.repo_sandbox.execute('git branch -D sphinx_export')
-        expected_msg = ("Warn: Pull request #23 is already closed.\n"
+        expected_msg = ("Fetching origin...\n"
+                        "Warn: Pull request #23 is already closed.\n"
                         "A local branch `sphinx_export` does not exist, but a remote branch `origin/sphinx_export` exists.\n"
                         "Checking out `sphinx_export` locally...\n"
                         "Added branch `sphinx_export` onto `comments/add_docstrings`\n"
@@ -2455,7 +2458,8 @@ class MacheteTester(unittest.TestCase):
             .push()
         )
         self.launch_command('discover')
-        expected_msg = ("Warn: Pull request #2 comes from fork and its repository is already deleted. No remote tracking data will be set up for `feature/allow_checkout` branch.\n"
+        expected_msg = ("Fetching origin...\n"
+                        "Warn: Pull request #2 comes from fork and its repository is already deleted. No remote tracking data will be set up for `feature/allow_checkout` branch.\n"
                         "Checking out `feature/allow_checkout` locally...\n"
                         "Warn: Pull request #2 is already closed.\n"
                         "Added branch `feature/allow_checkout` onto `develop`\n"