1

I'm new to Github and only push some commit to github. This is the first time I forked someone's repo. But after pushing some code on the forked one. I can't push my code on my own repo. I have already try the git rebase mentioned in this post. But all my code was deleted and covered by the files from the forked repo. I have recovered my files but still can't push on my repo.

The git status shows like this

Your branch and 'origin/master' have diverged,
and have 7 and 61 different commits each, respectively.

the following are my procedures. Please tell me if I have any mistake and how should I push my codes to my own repo and forked one ? I don't want to merge them because they are totally different repository.

  1. git clone github-address from forked repository
  2. git push origin master

[Edit] I have two repo on github. One is for my usage, the other one is the repo I forked. I change some code and push commit to the forked repo and then I can't push my code on another repo to github

I found something weird in git remote -v, and click these two urls they are all connected to the forked repo.

origin  https://github.com/xxxxxxxxx/VQA.git (fetch)
origin  https://github.com/xxxxxxxxx/VQA.git (push)

these are what I haved tried. Information from git reflog. I can't push commit after f66c72f

f66c72f (HEAD -> master) HEAD@{0}: reset: moving to f66c72f
f66c72f (HEAD -> master) HEAD@{1}: reset: moving to f66c72f
a4f1afd (origin/master) HEAD@{2}: reset: moving to origin/master
2697a7f HEAD@{3}: rebase: updating HEAD
2697a7f HEAD@{4}: rebase: aborting
f66c72f (HEAD -> master) HEAD@{5}: reset: moving to f66c72f
a4f1afd (origin/master) HEAD@{6}: rebase: checkout origin/master
2697a7f HEAD@{7}: commit: add resize_image.py
0d6e98a HEAD@{8}: reset: moving to HEAD^^
f66c72f (HEAD -> master) HEAD@{9}: reset: moving to f66c72f
f66c72f (HEAD -> master) HEAD@{10}: commit: add train.py file
a23ce98 HEAD@{11}: commit: add resize_images.py
0d6e98a HEAD@{12}: commit: add test.py file
5e09bad HEAD@{13}: commit: modify network architecture drop_out/activation
ad0525c HEAD@{14}: commit: rename
d3f0577 HEAD@{15}: commit: finishing data_loader
bbdbd9b HEAD@{16}: commit (initial): add make_vocab.py & preprocessing.py
Ian
  • 99
  • 11
  • Hmmm - I may have to rescind my answer - upon closer look I'm not sure what you mean by the forked repo (on github) and "my repo" - do you mean your local repo? You don't push to a local repo - do you have another copy of a repo that is separate from the fork? Read over the section on my answer about forked repos and let me know if the answer clears it up. – LightCC Jul 26 '20 at 18:13
  • I have two repos on github. one is for my usage, the other one is the repo I forked. I change some code and push to the forked repo and then I can't push my code on another repo to github – Ian Jul 26 '20 at 18:15
  • I will edit this into question – Ian Jul 26 '20 at 18:22
  • Okay, I get it now - two separate repos, one is your original repo, one is the fork of a different repo. Now my question is - how did they get confused? You should have two local repos, one for each remote repo - is that right? Or are you somehow trying to share code (but only some code) between the two remote repos? – LightCC Jul 26 '20 at 18:43
  • Yes, that's what you understand. I have two local repo. The question is when after I `git push origin master` to the github in my local forked repo, I can't push commit from another local repo – Ian Jul 26 '20 at 18:48
  • I find something strange and added it into [EDIT]. Maybe you can learn something from it. – Ian Jul 26 '20 at 18:51
  • Updated the answer (complete rewrite)... see if that answers it. – LightCC Jul 26 '20 at 18:55

2 Answers2

1

It appears you are trying to manage two completely separate remote repos in a single local repo. Unless the 2 remote repos are related (such as an original remote repo and a fork of that repo) with a common code base, that's not how git works.

You need to clone every remote repo you want to work in, into a separate local repo. Each one will be in it's own separate folder on your local PC, with it's own .git folder.

To share code between two unrelated repos, clone each locally, then just directly copy the code you want to reuse from the one repo to the other (locally). Then make a new commit in the target repo.

You need to manage fetch/push/pull completely separately for each local repo. From the command-line, you just need to be in a folder or subfolder of a given repo for git to work on that repo. Most GUI git tools only have one local repo open at a time (or per window).

[edit: complete rewrite of the answer! Hopefully got it right this time..]

LightCC
  • 9,804
  • 5
  • 52
  • 92
  • yes, I push commits using command line in the corresponding two different local folder. Now, the situation is I push commit to the github from my local forked repo, Then I can't push commit from another local repo . – Ian Jul 26 '20 at 19:01
  • I add some information to the question. Sorry for taking so much time – Ian Jul 26 '20 at 19:02
  • Make sure each local repo is initialized to the correct remote URL. If you switch the remote and then fetch or pull, it could rewrite your local history (and code). – LightCC Jul 26 '20 at 19:25
0

I solve the problem. The original name of my repo (I change its name after forked the repo) is same as forked one. So the remote URL is the same, if I push commits to the forked one, the other one will appear error.

The solution is to update the original repo remote URL (change name the URL will change, too) and it can successfully push without merging this two repository.

Ian
  • 99
  • 11