简体   繁体   中英

Pointing existing source code to remote .git repository

User A and User B have the same code. User A creates a repository ( git init , git remote add origin <repo-url> , git commit , git push in that order). Remote repository gets created and has the changes from User A.

User B already has the same changes locally but wan't to start pointing and getting tracked by the same repository. How does User B achieve that?

I tried a git init followed by a git remote add origin <repo-url> . git branch does not list any branches, not even master . What could be going wrong here?

The projects being added are already inside an existing Git repository. ie My project structure is Xdir/Ydir. Xdir is a Git repo. Everything I'm trying to do now is inside Ydir. That was not a problem for User A. But somehow User B is having issues pointing to it.

You have to fetch the branches to see them first. Once User B adds the remote branch do a

git fetch origin

to see the remote branches

It would be much easier for User B to start with git clone <User A repo-url> .

But if you really want to start with separate git init you should do git merge first.

User B should do:

git init
git add .
git commit
git remote add origin <User A repo-url>
git fetch
git merge origin/master

Now they can exchange their changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM