github branch restriction on personal account - github

I want to restrict commits to only few collaborators in few branches. I have personal account in github but donot have any facility to do so as that of organisation. Any suggestion is much appreciated.

You can always use GitHub's standard forking workflow:
Each collaborator will fork your repository and do their work in their own fork.
When something is ready to be contributed back to your repository the developer will create a pull request that you will review.
That code will only be merged into your repository if you approve it and accept the pull request.
In this way you control the code that gets merged into each of your branches.

Related

Can I set up Github repo to autoapprove and merge PRs from a specific user?

I'm working with hundreds of github repos (mostly Terraform) and every now and then I need to push a change all across those repos (typically version upgrade). Each has multiple branches and requires PR review before merge to master. Is there a way I can set it up so that PRs created by my automation account do not require approval before merge?
There is an hmarr/auto-approve-action action, which you can configure to auto-approve PR from certain users.
In your case, that could allow you to push as a dedicated user PRs that will be automatically approved by this action.

What are the proper GitHub settings to prevent people from committing to the master branch?

I want to set up a proper workflow on GitHub where junior engineers submit pull request for code review and only the lead engineer can commit to the master branch.
I'm looking for input from professionals that work in a commercial software environment. I've found the page that does the permissions easy enough. There are several options. Restrict who can push to matching branches of course. Should I check others as well?
The other approach, beside the branch permission within one repo, is the gate repo:
you are setting up a public repo where developers can commit (on master or topic branches)
you are using a private, or repo within an organisation, from which you can pull
That way, you or your organisation team control the contribution you chose to include in the master of that main repository.

Get the user who created a branch with GitHub API

Background
I am using GitHub Enterprise.
I want to check unused branches in my repository, and ask owners of these unused branches to clean-up.
You can see "Your branches" (branches created by current user) on “Branches” page in GitHub. So I think GitHub might have information for who created a branch.
On the other hand, the result of GitHub REST API (https://developer.github.com/v3/git/refs/#get-a-reference) does not contain the creator of the specified branch.
Question
Is there’s any way to get the user who created a branch with GitHub API?
There is no real "ownership" associated to a branch with Git/GitHub.
As mentioned in the documentation, "Your branches" reference in a repository the branches you have push access to, not necessarily the ones you have "created".
The best you can do is, if you have access to a local clone, a simple git fetch, followed by:
git for-each-ref --format="%(committerdate) %09 %(refname:short) %09 %(authorname)" --sort=-committerdate refs/remotes/origin
That will list the remote branches from the most recent updated one to the oldest, with the author of the last commit on each branch.
But if you have to use GitHub API, then you would need to:
list the remote branches,
then for each one get the commit mentioned with the branch
You can then contact the committer of that most recent commit.

Limit a collaborator to only push to a specific branch

Is it possible to set up a collaborator to only pull/push from a specific branch. Or for that matter, not be able to make changes to Master?
If your repository belongs to an organization, you can enable branch restrictions settings and choose who can push to restricted branches.
https://help.github.com/articles/about-branch-restrictions/
https://help.github.com/articles/enabling-branch-restrictions/
Revoke write access completely and make them fork the repository and submit pull requests.

How to work many users in the same feature in GitHub?

We are 3 developers working in the same feature in GitHub.
There is a master.
Each of the developers has their own fork of the master.
Now each developer added the remote fork of the other 2 developers. And with communication we are pulling the changes of the other 2 developers and then merging and pushing to the developer fork. So the others developers can pull and merge to push again to their fork.
The problem with this approach is that we have more merging to do, that if we were all pushing and pulling to the same branch. And the communication is a must.
We try to make a fork of a fork and we couldn't. Github does not support it.
We try to push to the same branch, we couldn't. It seems that also Github does not support it.
So there is a way in Github we all push and pull to the same branch or repository? And when we finish we do a pull request to a master?
Any recommendation about how to work many developers in the same feature in Github?
Instead of forking and pulling, you can use the other collaboration mode prevalent in GitHub: shared repositories. Shared repositories are useful for small, private development groups.
Give your developers push access to a central repository and they will be able to collaborate without pull requests and excessive merging. (Pull requests are still useful if you decide to use the shared repository model especially for code review and feature discussions.)
In GitHub terminology, a person able to push/pull from a repository is a collaborator. Collaborators are set in the repository settings page.
So there is a way in Github we all push and pull to the same branch or repository? And when we finish we do a pull request to a master?
Start an organization, move your repo there, and give all developers push access.