Serge Vinogradoff
Serge Vinogradoff

Reputation: 2272

Managing multiple users with GitHub

Can anyone please consult me on one thing?

We have a project, and we just decided to hire more programmers to work on it. Up to now I was the only programmer, backing up the code on GitHub. But now I need to find a safe way how to manage multiple programmers.

So there is a master branch of private project, which other programmers should be able to clone. But they should not be able to commit changes to master branch themselves. Perhaps they should make their own branches, and commit changes there. And I should be the only person who is able to review their work, and merge it to master branch if it works right.

Can anyone please tell me how exactly I should set it up? Or send some good tutorials? Thanks so much

Upvotes: 4

Views: 546

Answers (3)

jpaugh
jpaugh

Reputation: 7035

Collaborative coding is rather the whole point behind Github. Here's an illustrative workflow to get you started. A similar development flow is absolutely essential to open source projects (which by nature must work via the internet). In fact, a lot of open source projects use Github. You can use this process, too; although there are some caveats, which I've listed at the bottom.

The key to understanding this workflow is that each developer will manage 2 repositories:

  1. Personal work, on their local machine
  2. Work visible to all participants, hosted by Github.com

Setup process, integrator (project lead):

  1. Create github account
  2. Host project there

Setup process, developer:

  1. Create github account
  2. Fork the project
  3. git clone forked branch to local machine

Development process, developer:

  1. Work on local copy
  2. Push to github copy. (Remember, each developer has their own Github branch.)
  3. Submit a pull request to the project lead's Github repository.
  4. Rinse and repeat.

Development process, integrator:

  1. Look on Github for pull requests
  2. Review them, approve them, merge them
  3. Work on local copy, as above, sans the pull requests

However, this isn't the only possible workflow. For example, Github makes it convenient for your developers to send pull requests to each other, e.g. if two of them are working together on a feature. This way, all of them may work in the "integrator" role somewhat.

Caveats: If your program is not open source, then there is one caveat to using github: you must pay to host private repositories. They have a mechanism (disclaimer: never used) for organizing collections of people to work on either public or private repositories, however, and I believe the cost can be paid entirely in the organization owner — which would be great for your developers, and cost some extra for you.

If you only have a few contributers, you might be able to get by with having a free private repository by using Bitbucket instead of Github. They have an option to host private repos for free, and the workflow would be about the same as what I've outlined above.

Upvotes: 3

jmruc
jmruc

Reputation: 5836

When working with GitHub the best and easiest way is to use Pull Requests. In your case every programmer is given only Pull access to the repository, and has to cone it. When he or she is ready with the changes, that programmer sends you a pull request. You then review the request, and if ok merge it into the main repository.

Upvotes: 0

mproffitt
mproffitt

Reputation: 2527

The best way to achieve this is with a pre-receive hook which looks at the username of the person carrying out the commit and the branch they are trying to commit to. If the username isn't in a list of allowed users and the branch is the master branch then deny the push.

e.g.

#!/bin/bash
allowedUsers=( 'bob' 'john' 'george' ); # list of allowed usernames

while read oldrev newrev ref ; do
    echo ${allowedUsers[@]} | grep -q $(whoami);
    if [ $? -eq 1 ] && [ "$ref" = 'refs/heads/master' ] ; then
        echo "You are not allowed to push to master branch";
        exit 1;
    fi
done

Upvotes: 1

Related Questions