Home > Back-end >  git log says I have a fork but i dont
git log says I have a fork but i dont

Time:01-14

For some reason my git log shows that I have a fork/main branch, like so:

~ git log
commit abc123abc123 (HEAD -> main, origin/main, origin/HEAD)
Author: Me
...

commit xyz789xyz789 (fork/main)
Author: Me
...

But locally, I only have 1 branch (main), and on my private github repo, Forks shows 0. What is this thing and how do i get rid of it / understand it?

Probably related but when i do gh pr create, it offers me my repo as an option twice. This doesnt happen with my other private repos:

? Where should we push the 'testing' branch?  [Use arrows to move, type to filter]
> me/my-private-repo
  me/my-private-repo
  Skip pushing the branch
  Cancel

UPDATE:

~ git remote -vv
fork    https://github.com/me/my-repo.git (fetch)
fork    https://github.com/me/my-repo.git (push)
origin  https://github.com/me/my-repos-old-name.git (fetch)
origin  https://github.com/me/my-repos-old-name.git (push)

~ git branch -r
  fork/fix-types  <--- This PR was recently landed and the branch deleted, but never on any kind of fork (at least not that i know of)
  fork/main
  origin/HEAD -> origin/main
  origin/main

CodePudding user response:

The output of git remote -vv and the fact that you say you renamed your repo on GitHub is saying that fork is simply your local name for the remote with the new URL, and origin is your local name for the remote with the old URL.

From your commit log, it looks like you're still pushing using the old name, but that doesn't matter, because GitHub keeps the old name around as an alias whenever you rename a repo. That's to keep old sandboxes working.

There isn't actually a problem in all this, you could ignore it and keep going with pushing to origin using the old URL. But if you want to clean it up so it's less confusing, you can 1) remove the unnecessary fork remote, and 2) change the URL for origin.

  1. Run

    git remote remove fork
    

    to remove the fork remote from your sandbox.

    I think it's worth doing this, because the presence of this supposed (misnamed) fork in the logs will indeed continue to be confusing.

  2. Run

    git remote set-url origin https://github.com/me/my-repo.git
    

    to make origin point to the new URL instead of the old one.

    This is just for tidiness, but it will make no effective difference, since GitHub will keep the old name around forever (well, as long as you don't re-create a new repo with the old name later) as a redirect to the new name. But it will make things clearer in the future, and I guess it avoids using the redirect so it might be (a tiny bit) more efficient.

CodePudding user response:

You have 1 repository with 2 remotes origin and fork. This is different from having an separate repo made from the original 'upstream' repo - commonly know as forking.

Here are two options to get yourself to a single remote called origin:

  1. Manage the remotes. What @joanis said (remove->set-url) or:
    1. git remote remove origin
    2. git remote rename fork origin
  2. Clone the repo to a new folder (nuclear, but easy option)
  • Related