Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 611
Kobek Avatar asked Oct 31 '17 07:10

Kobek


People also ask

Do git pull before pushing again?

You need to pull before push, to make your local repository up-to-date before you push something (just in case someone else has already updated code on github.com ). This helps in resolving conflicts locally. 'origin' is a remote. You can use git remote --verbose to see all the remote configured under your git folder.

How do I pull latest changes in Github?

run git fetch to fetch latest changes, then run git rebase master to update your branch to the latest changes in master.

Does git checkout pull latest changes?

Indeed, git fetch pulls down the latest code from remote to origin/branch at local. If you have no local branch with the same name, then git checkout 2.1. 0 will create it for you, and checkout to that branch. But, if you have one already, then git checkout 2.1.


1 Answers

  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!

like image 193
Héctor Avatar answered Nov 08 '22 02:11

Héctor