So I have 2 branches on GitHub: master and branchA. Say I've been working on master and master is ahead by 3 commits or something. So there are commits d, e, and f on master that are not in branchA. Say next that my colleague uploaded branchA to GitHub with commit g. So we have:
master: a, b, c, d, e, f
branchA: a, b, c, g
Say now I want to switch to branchA and pull exactly what is on GitHub. The issue I'm running into is when I use git branch branchA
it will automatically use master as my starting position and thus add d,e,f and when I pull branchA I get conflicts as g and d,e,f are not yet compatible.
Is there a way to pull from GitHub such that my local commit log matches that on GitHub? I tried git pull -f
but that obviously didn't work either.
you should
git fetch
then inspect what has transpired with something like
git log --all --oneline --graph --decorate
Now you can merge or rebase the work that was done at the same time. Any branches prefixed with "origin" will be what's on github (assuming that's where you cloned from). Local branches will be coloured differently too.
If you want to work a branch that was pulled down that you haven't worked on yet, check it out and track it in a local branch with
git checkout -t origin/someBranch
I would only use pull in exceptional cases where I'm merging or rebasing my own work. Depending on what someone else did, I may choose rebasing over merging.