Search code examples
gitmergeversion-controlbranching-and-merginggit-checkout

Git get latest changes before pushing a branch


I have a local branch features that I based off of my local master to add some stuff in my code. I am now ready to merge those back into master , however, the state of the remote master branch has changed since then.

How can I get the latest version of master and then add my changes on top of that, so that I can then make a pull request to my remote master branch.

I read a couple of similar articles here, but all of them gave different answers and I got confused.

Should I first "switch" to my master branch, do a git pull and then somehow merge my features branch into it (resolving any conflicts), or is there another way.

Some articles pointed out the usage of git checkout branch features, but I am not sure what is the point in that. As far as I understand it git checkout just switches to a certain branch.

Can anyone point me in a correct direction as to how I might approach this. Again, I just need to get the latest changes of my remote master branch so that when I push my features branch I dont get a ton of conflicts.


Solution

    1. Go to master branch with: git checkout master
    2. Update your local master with: git pull origin master
    3. Resolve conflicts (if applicable)
    4. Go back to features with: git checkout features
    5. Merge master branch over features with: git merge master
    6. Push changes with: git push origin features

    Now, you have to create a new pull request from features to master. Done!