2

Goal: A jenkins pipeline that forks a repo, makes a change, pushes the change and generates a PR from master.

My issue is that since this may run in parallel, I need each fork to have a unique name. The gh command-line tool seems to indicate this is possible with the --remote-name flag, but it's not doing what I'd expect and I don't know if there is another way

My command gh repo fork https://host/team/aws.git --remote=true --clone properly creates a user/aws repo, however gh repo fork https://host/team/aws.git --remote-name=ME-test --clone returns user/aws already exists

Is there another way to achieve a renamed fork?

torek
  • 448,244
  • 59
  • 642
  • 775
amacks
  • 80
  • 5
  • Why not use a single fork with different branch names? – knittl Oct 20 '21 at 19:12
  • I was hoping to make each job atomic: fork, commit, push, PR to the original. If I've got a long-lived fork and use branch names, I then need to keep the fork in-sync with the master, and I'm not sure how to do that – amacks Oct 20 '21 at 20:23
  • Note that Git itself doesn't have forks (they're a GitHub-specific feature - although duplicated on many other hosting sites too...) so any answer here is specific to GitHub. – torek Oct 20 '21 at 21:53
  • Do you _have to_ use a fork? Does your pipeline have write access to the upstream repo? If so, the branch could be pushed directly to the upstream and you would always have the most recent version. If a fork is required, then `git fetch $upstream_url remote_branch:local_branch` would update your local (fork's) branch with commits from upstream. TBH I'm not aware of the fact that GitHub allows giving forks a different name, they are always called `$user/$reponame` with `$reponame` being the upstream name (I could be mistaken though) – knittl Oct 21 '21 at 05:20
  • We had hoped to use a fork so the pipeline wouldn't need any write permissions to the main repo – amacks Oct 21 '21 at 17:24
  • @knittl "TBH I'm not aware of the fact that GitHub allows giving forks a different name, they are always called `$user/$reponame` with `$reponame` being the upstream name": it is actually [possible since Apr. 2022](https://stackoverflow.com/a/71849165/6309). – VonC Apr 12 '22 at 21:25
  • @VonC thanks for the heads-up! It's interesting that I wrote this comment a year after I answered a different question with "it's possible". :) But I still think _this_ question could do without multiple forks by creating different branches. – knittl Apr 13 '22 at 05:28

1 Answers1

0

Check if the GitHub CLI gh 2.5.0 (Feb. 2022) would help with gh repo fork

PR 4886 proposes:

adds the functionality to add a --fork-name flag to specify what the final name of the forked repo should be.

Since the Github API doesn't yet support this automatically via the Fork API, we fork it and later rename it via the Rename API.

This fixes issue 4849.

That command supports creating a fork with a different name.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250