I just moved from a project that was on SVN to git. Having not much git experience or command line experience, this was a little stressful. Especially since this project was using a form of git workflow called "git flow". More about git flow here.
Oh and this all goes on top of the everyday stress I always get thinking “Do I know how to build this? “or “ What if I can’t build it in time?” The answer is mostly yes. It just takes time.
So here is what happened. I made my changes in my feature branch but forgot to keep them up to date with the develop branch. I did git pull origin develop to try and update my changes and followed a rebase tutorial and ended up with the dreaded “develop branch and “origin/develop” have diverged. I somehow was 12 commits behind and 5 ahead. I really messed up and had no idea how to fix it. The first thing I thought was okay, don’t panic this is only on your local machine, it’s not like you pushed any changes up (even if I did, it’s easy to roll back changes).
git revert Which undoes a committed snapshot by undoing the changes introduced by the commit and appending a new commit with the resulting content.git reset Which was a permanent undo. As if my mistake never existed, which is exactly what I wanted! Since it was only on my local branch I decided to go with this method. More on git reset here.git pull origin develop
I then fixed any merge conflicts manually. You can find them with conflict markers that start with <<<<<<< and end with >>>>>>>
Alright, things are looking hunky dory in my feature branch. Now to actually merge the changes into develop.
git checkout develop
git merge feature/yourfeaturebranchname
git pull origin develop, It only brings in the feature branch changes instead of bringing develop up to speed and also merging the feature branch.git push origin develop
I highly suggest that you use the command line if you currently use a GUI application. Its faster and much easier to troubleshoot when you can paste the exact error code you get into google. What I did was run the command and then see how it updates in the GUI application, I used sourcetree. If you want an intro to what git is there is an excellent write up at Luke Towney’s blog here. Please comment with any questions or comments, I'm still learning and their may be an even better way to do this. Thanks!