4

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

3
  • 3
    The easiest way would be to have the collaborators fork your repository and use pull requests. No need to use branches for this.
    – James M
    Jun 9, 2013 at 12:31
  • Thanks a lot. Will read about them. Jun 9, 2013 at 12:34
  • See also GitHub 2022 Entitlement new feature.
    – VonC
    Jun 9, 2022 at 20:00

3 Answers 3

3

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.

4
  • 1
    About your disclaimer: if one forks a private repository, the fork is also private, and does not count as a separate private repo for anyone(no additional payment).
    – jmruc
    Jun 9, 2013 at 13:19
  • Do you know how I can let users fork private repository? I just saw that they can't access the private project by URL (simply 404 error), unless they are marked as collaborators. But collaborators can not only fork but also commit to the main repository which is what I need to prevent. Do I need to register a company account or something? Jun 9, 2013 at 13:25
  • @SergeVinogradoff My mistake, you can only do this with organizations - github.com/blog/674-introducing-organizations. If the repository belongs to an organization, you can create a team with read-only access to the repo.
    – jmruc
    Jun 9, 2013 at 15:54
  • Yes that's what I did. Great tool. Thanks! Jun 9, 2013 at 16:55
1

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
1
  • If you are suggesting this as access control, then I have to disappoint you as this is gonna get broken in two seconds if someone really wants to. Jun 9, 2013 at 12:41
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.