renaming a command-line git fork with gh
Asked Answered
C

1

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?

Coralloid answered 20/10, 2021 at 18:33 Comment(7)
Why not use a single fork with different branch names?Nikola
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 thatCoralloid
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.Spongioblast
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)Nikola
We had hoped to use a fork so the pipeline wouldn't need any write permissions to the main repoCoralloid
@Nikola "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.Zayas
@Zayas 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.Nikola
Z
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.

Zayas answered 1/2, 2022 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.