2

FYI: I am using bitbucket to push my git to (I know not very important).

I was working on a project, wherein I made changes, and pushed to origin master, only to realise that master had some major bug, hence I checked out to a specific old commit, in the same master branch by using

git checkout commit_name

After that I started working further and kept adding and committing, now I am lost how to keep the following new commits, as well as not lose earlier (buggy) master. Basically how to get back on track.

P.S. I tried using git push -u origin master , but it returns Everything up-to-date, and nothing gets pushed to bitbucket.

1 Answers1

2

I guess you are on detached head. When you did git checkout commit_name, you updated your local repository to checkout the code of commit_name but you are not on any branch. You are in freestyle way and can only do limited action. You need to go back on your master branch.

  1. git checkout -b branch_tmp to move to the new created branch branch_tmp
  2. git rebase master to apply your last commits on top of master
  3. git checkout master
  4. git merge branch_tmp to update your master branch with commits done previously and present on branch_tmp
  5. git push origin master
  6. git branch -d branch_tmp to clean your repository

In any step, I advice you to have a look to log history to understand different action performed.

You could find more information about detached head there

Flows
  • 3,675
  • 3
  • 28
  • 52