lks128
lks128

Reputation: 986

How to use git for multiple developers

Here is very simple question for experienced Git user. I've created repository on git hosting and set up mine pc:

git init
git remote add origin git@*.sourcerepo.com:*/ *.git

Then, after some changes I do:

git add .
git commit
git push

All these actions are done on first developer pc.

Now the question: How does second developer access and take changes to repo? First of all he has to clone repo?

Upvotes: 3

Views: 2194

Answers (3)

VonC
VonC

Reputation: 1328562

Beware of option when multiple developers are applying patches:
With Git 2.30 (Q1 2021), "git apply" adjusted the permission bits of working-tree files and directories according core.sharedRepository setting by mistake and for a long time, which has been corrected.

apply: don't use core.sharedRepository to create working tree files

core.sharedRepository defines which permissions Git should set when creating files in $GIT_DIR, so that the repository may be shared with other users.

But (in its current form) the setting shouldn't affect how files are created in the working tree.

This is not respected by apply and am (which uses apply), when creating leading directories:

$ cat d.patch
 diff --git a/d/f b/d/f
 new file mode 100644
 index 0000000..e69de29

Apply without the setting:

$ umask 0077
$ git apply d.patch
$ ls -ld d
 drwx------

Apply with the setting:

$ umask 0077
$ git -c core.sharedRepository=0770 apply d.patch
$ ls -ld d
 drwxrws---

Only the leading directories are affected.
That's because they are created with safe_create_leading_directories(), which calls adjust_shared_perm() to set the directories' permissions based on core.sharedRepository.

To fix that, let's introduce a variant of this function that ignores the setting, and use it in apply.
Also add a regression test and a note in the function documentation about the use of each variant according to the destination (working tree or git dir).

Upvotes: 0

MattG
MattG

Reputation: 1322

Yes, you would use clone. You also should be sure to set the sharedrepository config option:

git config core.sharedRepository "true"

You should also be aware, with multiple commiters that the fetch option would let you preview the changes in the main repository, and how they would apply to you:

git fetch
git diff origin

or you may want to simply see a list of files and diff each one seperately:

git diff --name-status origin

Upvotes: 6

innaM
innaM

Reputation: 47889

Yes. It's going to be

 git clone $giturl
 git add .
 git commit
 git push

for him.

Upvotes: 4

Related Questions