I want to disable commits for certain branches in github and only allow merging via Pull Requests. I can do this in VSTS Git repos, but how do I do the same in GitHub? Is this even possible?
In your repositories settings, you can go to "Branches" in the left menu.
Then you can add a "Protected Branch", and then check "Require pull request reviews before merging".
Then nobody will be able to commit on this branch unless they made another branch and submitted a Pull Request.
Related
My commit button is not getting enabled after editing Readme file in github.
The reason why the commit button is not enabled is because you are trying to commit to the master branch of the repo, which is protected from making direct commits/push. Only those who have access to make direct commits to master can do that, and you might not have that access. Hence you need to select the second option there to create a new branch to make the commit and create a pull request to the master branch, or get access to directly contribute to that branch.
The branch protection is to ensure that collaborators don't directly push or make commits to the particular branch or delete it, and also allows enabling status checks or required reviews. You can read more about GitHub's branch protection here.
I am trying to configure a GitHub repo so only certain users can push to a certain branch.
The branch pattern name matches the branch I want to restrict.
Here is a screen shot of the protected branch settings:
Yet, I can still can create a pull request from any branch and merge to the protected branch.
This is an organizational repo which I have admin privileges. Can only an organization maintainer change a branch's protected settings? Is there something else that needs to be configured?
I think this is by design. The "restrict who can push to matching branches" feature limits who can push to a branch, but you say
Yet, I can still can create a pull request from any branch and merge to the protected branch.
The whole point of protecting branches is to force code to go through a pull request process. Restricting push access doesn't restrict pull requests. It simply means users can't git push code directly to the branch.
You can also add required status checks before pull requests can be merged, e.g. for tests to pass, for a certain number of collaborators to approve the pull request, for commits to be cryptographically signed, etc.
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.
I have 2 branches in my github repository. How do I enforce a branch policy for Master branch such that any changes to it must require a code review from specific folks done ?
This is best managed by repos, not branches.
You can have one repo with the master branch, and one or several forks, from which developers can make pull request in order to request a merge to master of the original repo.
Only the "specific folks" are declared collaborators on the original repo, and can review the PRs and merge them.
Then the developers can synchronize their own fork.
I want to clone/merge branch for my git repository inside github, for example merge updates in draft branch to gh-pages for publish.
And in some cases, I don't have access to command line for git command.
Is it possible to achieve this online ?
You can merge branches in GitHub using a Pull Request as long as the merge doesn't create any conflicts.
To merge a pull request on GitHub:
Create a Pull Request to merge the draft branch into the
gh-pages branch.
If it can be merged online, you'll see This pull request can be automatically merged. and a Merge pull
request button.
Click the button and you'll have a chance to Cancel the merge or add a commit message and Confirm Merge.
If you choose to Confirm Merge, the Pull Request will automatically close.
For more information, visit Github's Merging a Pull Request Help page.