Reputation: 109
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.
git clone
github-address from forked repositorygit 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
Upvotes: 1
Views: 1946
Reputation: 109
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.
Upvotes: 0
Reputation: 11689
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..]
Upvotes: 1