0

Context: I am working with git. I typically have forks of other repositories where I contribute now and then. I switch my work machines often - and also delete local clones of the remote repositories. When I want to resume work, I need to do following:

  1. git clone https://github.com/example-upstream/repo
  2. cd repo
  3. git remote rename origin upstream
  4. git remote add origin https://github.com/example-fork/repo
  5. git fetch origin
  6. git push origin # to push the main branch from upstream to origin

For step 6, there is git-town sync. I checked hub and gh.

1 Answer 1

1

The solution is to use gh repo clone <fork-url>:

gh repo clone https://github.com/example-fork/repo

This does all of steps 1 to 5:

$ gh repo clone https://github.com/example-fork/repo 
Cloning into 'repo'...
remote: Enumerating objects: 410, done.
remote: Counting objects: 100% (151/151), done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 410 (delta 80), reused 139 (delta 78), pack-reused 259
Receiving objects: 100% (410/410), 79.42 KiB | 2.48 MiB/s, done.
Resolving deltas: 100% (212/212), done.
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 16 (delta 9), reused 15 (delta 9), pack-reused 0
Unpacking objects: 100% (16/16), 4.33 KiB | 119.00 KiB/s, done.
From github.com:example-upstream/repo
 * [new branch]      master         -> upstream/master
 * [new tag]         release-2023.2 -> release-2023.2
! Repository example-upstream/repo set as the default repository. To learn more about the default repository, run: gh repo set-default --help

Install it on Windows using winget install --id GitHub.cli.

More installation instructions: https://github.com/cli/cli#installation

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .