This is a simple guide to setting up Git repositories in which multiple users of a server can have access to. I've been running into many problems setting these up myself, so this is more of a reminder to myself and may be of some use to others.
First, we need to prepare the users by grouping them into a project group so we can control access via this group. For our project, we'll create a group (here, "git") and add the users to the group.
(Note: The following actions happen on the server)
# create the git groupgroupadd git# add users to the groupgroups user1 -aG gitgroups user2 -aG git...
We set up an empty project named gitproject. I'm setting up git projects in /var/git, but you may do this somewhere else, such that it is accessible to all users as well.
(The following actions happen on the server)
cd /var/gitmkdir gitproject.gitcd gitproject.gitgit init --bare
We can now make sure that this directory is accessible to the group members
cd /var/gitchgrp -R git gitproject.gitchmod -R g+swX gitproject.git
Now we can come back to our local machine, create a local git repository, and start pushing and pulling code from/to the "origin" repository
First, we'll set up a local git repository.
(All of the following actions happen on your local machine)
mkdir gitprojectcd gitprojectgit init
Now, we add our server's repository as the remote repository for our project:
git remote add origin user1@remoteserver:/var/git/gitproject.git
so we can pull the "master" branch at this "origin" repository:
git pull origin master
At this moment, your local development directory contains the same stuff as there is in the remote git repository, and you can start committing code to your local repository and pushing that into the remote repository (using git push origin master) and pulling updates from the remote repository into your local repository (using git pull origin master).
If you add the following three lines to your "./.git/config" file you no longer have to provide the "origin master" repo/branch details at every push or pull:
[branch "master"]
remote = origin merge = refs/heads/master
And now for some basic git commands:
git pull # pull diffs from remote repo to local repo
git commit -am "my comment" # commit to local repositorygit push # push diffs from local to remote repo
git add newfilegit commit -am "added newfile"git push