1

I'm writing a test script for a CI/CD system and need to checkout the source and target branches of a pull request and do some verifications.
I would like to have fixed branch names in my local repo (src and target) and hence I use refspecs with a target branch for my fetches. But additionally to my target branch git also fetches into a target branch with the original name of that branch (marked bold below). In the git fetch manpage I didn't even find a hint that git should behave this way. This issue leads sometimes to name conflicts and I want to avoid that.


+ git fetch --no-tags -f origin feature/some-feature:refs/remotes/origin/src
From github.com:user/repo
 * [new branch]        feature/some-feature -> origin/src
 * [new branch]        feature/some-feature -> origin/feature/some-feature
 
+ git fetch --no-tags -f origin master:refs/remotes/origin/target
From github.com:user/repo
 * [new branch]        master    -> origin/target
 * [new branch]        master    -> origin/master

How can I make git stop fetching into branches with original names from remote and use only the target branch names I explicitly mention (how to remove bold lines)?

Federico
  • 138
  • 1
  • 12
  • 1
    Why exactly is this necessary? It is good to be up to date on every branch. – Peter Nielsen Apr 07 '21 at 19:43
  • @PeterNielsen The repository is >10gb big with many thousands of commits and also that many branches and hence I don't want every branch. To check a pull request I only need the source and target branches of that PR. – Federico Apr 07 '21 at 19:54
  • 1
    Does this answer your question? [How do I fetch only one branch of a remote Git repository?](https://stackoverflow.com/questions/6368987/how-do-i-fetch-only-one-branch-of-a-remote-git-repository) – Peter Nielsen Apr 07 '21 at 20:06
  • I believe [this](https://stackoverflow.com/questions/6368987/how-do-i-fetch-only-one-branch-of-a-remote-git-repository/26270966) is an answer. Duplicate question. – Peter Nielsen Apr 07 '21 at 20:07
  • @PeterNielsen no, you didn't understand my question. I already fetch single branches all the time. My problem is the naming of the fetched branches. – Federico Apr 07 '21 at 20:10
  • 1
    View `git config -l` in the repository. There should be a line including `+refs/heads/*:refs/remotes/origin/*`. If there is, remove that config value. – ElpieKay Apr 08 '21 at 06:50
  • @ElpieKay this seems to solve it. At least adding `--refmap=` to my fetch command does. Please add your comment as a solution so I can accept it. From the docs: `Providing an empty to the --refmap option causes Git to ignore the configured refspecs and rely entirely on the refspecs supplied as command-line arguments.` – Federico Apr 08 '21 at 18:27

0 Answers0