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.
-
Create a new branch from the current HEAD detached branch. Eg :
git branch tmp git-hash-id
-
Delete remote branch
git push origin --delete tracing
-
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
-
Create a local branch called and checkingout to it
tracing
git checkout -b tracing
-
Merge the codes from
tmp
branch. Eg :git merge tmp
. -
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
Post a Comment