![]() To create a new branch from the branch you DO have checked out: git branch new_branch What I call is what they call, and what I call is what they call : git branch Ģ. To create a new branch from a branch you do NOT have checked out:Ĭreate branch2 from branch1 while you have any branch whatsoever checked out (ex: let's say you have master checked out): git branch branch2 branch1 While I'm at it, I'll also add my other most-common git branch commands I use in my regular workflow, below. This isn't touched upon well, if at all, by any other answer here. I'm adding this because I really needed to know how to do #1 below just now (create a new branch from a branch I do NOT have checked out), and it wasn't obvious how to do it, and Google searches led to here as a top search result. ![]() This answer adds some additional insight, not already present in the existing answers, regarding just the title of the question itself ( Create a branch in Git from another branch), but does not address the more narrow specifics of the question which already have sufficient answers here. The new feature is not in the repository and I can create a pull request into develop to check the changes live before finally merging them into production.Various ways to create a branch in git from another branch: Git push origin article-protect-git-branch Git checkout -b article-protect-git-branch Having the master and develop branches I will pull my develop branch and then create another branch for the work I want to work on, for example: git checkout develop This is a simple solution for me to at least protect those branches I want to and forces me to create PR's everytime I want to make a change. You could do the same for the develop branch to also protect that. A simple if statement and stop pushing directly to the master branch and you will need to create a pull request to merge changes. The script checks the current branch being pushed and compares it to the protected branch, in this case master. If Įcho "$ is a protected branch, create PR to merge" git/hooks folder you need to create a file pre-push, no file extension and add the following to the file: #!/bin/bashĬurrent_branch=$(git symbolic-ref HEAD | sed -e 's.*/\(.*\),\1,') You should be left with two rules that have nothing currently checked but this will protect both of these. Master branch will also need to be protected in the same way. This will now protect the branch from being deleted. In Branch name pattern add the text develop without selecting anything else. The next step is protecting the develop branch from deletion by simply creating a Branch protection rule by clicking on the add button. I just prefer doing it this way to further protect the master branch. This is of course optional and you could leave the master as default. Once the develop branch is in the repo you want to navigate to Settings > Branches and set the develop branch you just created as default. You could also do this by simply creating a branch from the GUI. ![]() My first step is creating the develop branch from master and pushing this up to Github. ![]() So this is just a note to myself how to create this setup and it might be of some use to anyone else trying to organise their process a bit without making things to complicated. I setup develop as my default branch and the master branch is what is deployed as Production by merging changes from develop. I still have plenty to learn but the basic idea is that I have 2 main branches master and develop. I've only really ever developed application by myself but I work in a way that I hope to be able to work in a team. Home Articles Pantry Series Protect git branch and prevent master push Background #
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |