Git mistakes - 1

Git mistakes - 1

Hello Coders…

I hope you are having a great weekend. Today I am going to talk about My Git mistake.
I was working with a project where I tried to add opentracing to it (which is still not working properly).
First I created a new branch from my development branch using :

git checkout -b tracing
Then tried to add opentracing to it, there were many errors and I was fixing one by one and committed all the codes properly.

At certain point I had to revert my git branch to a previous commit I made. Then I was working on that. Didnt merge the commits back to original tracing branch.
When I try to merge them with my tracing branch, I was getting a lots of errors. Tried to fix them (merge conflicts), but they were not working as expected.

Finally I found a solution for this problem. This is kind of shortcut.

  1. Create a new branch from the current HEAD detached branch. Eg : git branch tmp git-hash-id

  2. Delete remote branch git push origin --delete tracing

  3. Delete local branch git branch -d tracing
    You will probably get an error :

    error: The branch ‘tracing’ is not fully merged. If you are sure you
    want to delete it, run ‘git branch -D tracing’

    And git is smart enough to give us the answer.
    git branch -D tracing

  4. Create a local branch called and checkingout to it tracing
    git checkout -b tracing

  5. Merge the codes from tmp branch. Eg : git merge tmp.

  6. Push new changes to newly created tracing branch in remote . Eg : git push origin tracing

Let me explain what is happening here.
First we create a new branch from currrent detached head.
Delete missed branch (locally and remote)
Create a new branch and merge code from tmp branch.
Push changes to remote server.

I am not a git expert, I am still learning them. This SO thread helped me to slove this issue.

Written with StackEdit.

Comments

Popular posts from this blog

Youtube-dl cheatsheet

Docker Development - Mistakes 1