Git Branches
Creating a New Branch
$ git branch
$ git branch (name of new branch)
$ git checkout (name of new branch)
$ git push origin (name of new branch)Merging branched branches to master
masterSituation:
You have a
masterbranch, afeaturebranch, and afeature2branch that branches from thefeaturebranch (NOTmaster)How do you safely merge the
featurebranch andfeature2branch intomasterand delete these branches?
Concept:
Open PR for
featurebranchGet code review back for
featureand add and commit tofeatureas you resolve the code reviewAs you add and commit to
feature, you have to also keepfeature2in sync withfeature. So as you add and commit infeature,git pullinfeature2fromfeatureOnce the code reviews are completed, merge
featurebranch intomasterYou cannot delete
featurebranch yet sincefeature2's parent branch isfeatureGo to the PR for
feature2and changefeature2's parent branch tomasterusing the dropdown on GithubNow,
feature2only depends onmaster, so you can now go to the PR forfeatureand safely delete thefeaturebranchNow do code review for
feature2and merge intomaster.Delete
feature2.
Keeping child branches up to date with the parent
Git checkout into parent branch and pull
$ git checkout parent-branch
$ git pullGit checkout into child branch and pull
$ git checkout child-branch
$ git merge origin/parent-branchSolve any merge conflicts and push commit.
Get parent branch
Note that this functional is kinda "hacky" and is not a solid solution. It just finds the branch that was merged closest.
git log origin/master --pretty=format:'%D' origin/<branch_name>^Get branch stats different from master
git diff master origin/<branch_name> --shortstatLast updated
Was this helpful?