1

I am struggling to properly switch to my forked version of a repository. I was following the instructions here for how to do so, but I seem to be running into a few errors.

I was able to run

git remote add my-fork git@github...my-fork.git
git fetch my-fork

But when I tried

git push my-fork

I got the error

To github.com:...my-fork.git
 ! [rejected]              master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:...my-fork.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I tried a number of online suggestions, including

git pull
git pull --rebase
git fetch origin
git merge origin master

These all gave the message "Already up to date." How do I resolve this?

student1868
  • 197
  • 1
  • 3
  • 12
  • Does this answer your question? [Cannot push to GitHub - keeps saying need merge](https://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge) – phd Dec 14 '19 at 10:27

1 Answers1

0

Sounds like your fork does not have the same commits as the repository you are working on.

You can force your remote to match your local repository by using git push -f.

note that this can make you lose commits you have on your fork if they are not present on your local repository.

gkpln3
  • 1,317
  • 10
  • 24
  • This does not work for me. I get the error `fatal: remote error: service not enabled: /git/.git` – student1868 Dec 13 '19 at 20:05
  • @student1868 Can you double check your remote address? Try calling `git remote -v`. – gkpln3 Dec 13 '19 at 20:06
  • Okay, so when I tried `git push my-fork -f`, it worked, but I am having trouble properly switching to a branch on the fork. When I try to run `git checkout my-fork/master`, I get the a detached HEAD. – student1868 Dec 13 '19 at 20:09
  • You get a detached HEAD since you are not creating a new local branch, but moving to a reference pointed by remote. To move to your fork branch, you can use `git checkout my-fork/master; git checkout -b master` – gkpln3 Dec 13 '19 at 20:10