GIT: Finding Parent Branch

Tagged as: ,

When you create a branch in git, using command such as:-

git checkout -b branch1

Git will create the new branch based on our current branch, usually the master branch. But it possible at the time we created the branch, we’re not on master branch. So to figure out what is the branch origin/parent, we can use this command:-

current_branch=`git rev-parse --abbrev-ref HEAD`
git show-branch -a | awk -F'[]^~[]' '/\*/ && !/'"$current_branch"'/ {print $2;exit}'

Reference - http://stackoverflow.com/questions/3161204/find-the-parent-branch-of-a-git-branch

Written on December 7, 2015 by kamal
About author

Lead Engineer at Xoxzo Inc. Develop web applications in Python/Django. Interested in open source and tech talent development.

Xoxzo.com provide API services for developer to develop messaging and voice based application. The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions. I can be reached via Twitter @k4ml.

Ikuti perkembangan terkini melalui twitter kami @koditi atau FB Page fb.me/koditi.