I have a local git repository on my computer. Is that possible my friend set his upstream to my local repository on my computer and my local repository becomes his remote repository?
So he will be able to get the latest changes from my local repository and push to my local repository. (I don't want to use tools like github
or gitlab
or ...)
Asked
Active
Viewed 475 times
4

Mohammad Taherian
- 1,622
- 1
- 15
- 34
-
Yes. It is not only possible, it is a common use case. – William Pursell Sep 23 '20 at 16:33
-
@WilliamPursell Thank you for the answer. How can I do that? and why downvote? – Mohammad Taherian Sep 23 '20 at 16:46
-
1I didn't downvote, but I would speculate the downvote is because the question lacks clarity. If you want a detailed answer, you should ask a detailed question. What have you tried? What errors did you get? What you are trying to do is pretty trivial, so it's not at all clear what you're having trouble with. – William Pursell Sep 23 '20 at 17:04
-
@WilliamPursell Sorry for misunderstanding. Honestly, I didn't try. I tried to find a solution but I couldn't. That was why I asked this question here, to know if it is possible or not and if the answer is yes, How I can do that. – Mohammad Taherian Sep 23 '20 at 17:08
-
You just do it. :) `man git-daemon`. But it might be easier to pass bundles around, or patches. There are a lot of mechanisms for passing commits between repos. – William Pursell Sep 23 '20 at 17:12
1 Answers
2
The short answer: you can.
The long answer: you need to do a little bit more than just letting your friend add your local repo as his remote. The reason is that you always want to use a bare repo for multiple users to interact with. See this, and this for more detailed explanations.
Suppose your local repo is located under ~/projects/my-working-repo
, you want to do this:
cd ~/projects
mkdir public-repo
cd public-repo
git init --bare
cd ../my-working-repo
git remote add origin $HOME/projects/public-repo
git push origin --all
Now all the history in your local repo are in public-repo
. You and your friend can push commits to, and pull from public-repo
. my-working-repo
will remain your own working area.

jingx
- 3,698
- 3
- 24
- 40