Question
I have two different folders with different paths and I want to link them to the same repository. For illustration purposes, the two different folders are
Folder 1: C:\Users\Tea\Folder1
Folder 2: C:\Users\Tea\Folder2
Folder 1 was originally linked to my repository but I wanted to link Folder 2 to the repository too so I can push a file from there as well.
Here's what I tried
cd C:\Users\Tea\Folder2
git init
git add .
git commit -m "initial commit from Folder 2"
git remote set-url origin --push --add http://github.com/<my username and repository>
The last line was done according to this post: pull/push from multiple remote locations
However, I got an error message when doing
git push origin master
asking me to do a git fetch. More specifically it wrote:
! [ rejected ] master -> master(fetch first)
error: failed to push some refs to 'https://github.com/...'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull...') before pushing again
So I did git pull origin master
and got these messages instead
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 merging but got
fatal: refusing to merge unrelated histories
so I decided to do
git push -f origin <branch>
according to Cannot push to GitHub - keeps saying need merge without knowing exactly what "losing all commits" meant (I thought it just meant that the current commit messages would be lost).
Turns out this was a bad decision on my part since the new folder I linked to the git repository just replaced my old git repository entirely (i.e. all the old files are now gone).
tl;dr: How do I link two separate folders to one Github repository? Thanks in advance!