Reputation: 75
I am on master branch and I did 2 local commits(not pushed) on top of commit which is pushed to remote. I want to to get my local working master branch in sync with remote.So i ran the command
git checkout HEAD~2
I am successfully able to get my current working branch to 2 commits back and is in sync with remote master but locally i am seeing that i am working on "no branch"
gakaushik@L-MAA-00438612 /c/legacytxn/PayPalOneSpot/OneSpot ((db39c78...))
$ git branch
* (no branch)
master
Because of this i am not able to do further pull/push operations associated with this branch.Can someone please tell why is this behaviour ? I am new to git so kindly tell me if my understanding is wrong in anyway ?
Regards Gaurav Kaushik
Upvotes: 2
Views: 563
Reputation: 982
To get what you want,run this command:
git checkout -b newBranch && git reset --hard HEAD~2
Safe version:
git checkout -b `date +"%m-%d-%y-%s"`
git commit -am 'automatic';
git checkout master;
git pull;
git checkout -b newBranch && git reset --hard HEAD~2;
Upvotes: 2