This trick I use time by time, and I want to share it with you.
Sometimes when I review someone’s code, the code got updated remotely. So I git pull
, and I just found out there are a lot of conflicts, and it’s really hard to resolve these conflicts.
I don’t want to resolve those conflicts, and I just want the latest code! What can you do?
Maybe the easiest but also time-consuming way is to git clone the new repo again. I know the new repo will have the latest one and then I can switch to that branch.
And below is another way I learned and way quicker:
Since the problem is about the branch, so we can just remove the branch!
Firstly, we can just commit all changes whatsoever (regardless of the conflict, just clean up the git staging, and revert all changes).
Then we switch to master, and then remove this broken local branch. Finally, I can git pull again and switch back and get the latest update from that branch!
See the below snippet:
# just git commit all stuff whatsoever
git add .
git commit -m 'temp'
# go master
git checkout master
# find the branch in case you want to copy paste the branch (beanch name could be lengthy)
git branch
# delete it
git branch -D branchName_1_2_3
# pull the latest one and check out to that brancg again, problem solved!
git pull
git branch branchName_1_2_3
Let me know if you have other thoughts on this!
Thanks for reading!
Top comments (0)