Tuesday, April 19, 2016

How to swap changes on tracking branch to another remote and reset previous tracking branch

I was working in GIT remote tracking branch without pushing the changes to it's origin. A requirement came to share those changes with another developer with a separate remote branch. That means I need to create another remote branch with my changes. Following are the commands I used to do it.

git checkout current_origin_branch

git pull

git checkout -b new_feature_branch

git push -u origin new_feature_branch

git checkout current_origin_branch

git reset --hard origin/current_origin_branch

Above requirement will not be raised, if you are always creating local branches from the tracking branches for your feature developments.