Rebecca Eliscu
Rebecca Eliscu

Reputation: 195

Github: How to get local to reflect a remote branch

I made changes that I don't want to continue with, so I want my branch, rebecca_dev to be updated to match the upstream dev branch. I then want those changes to rebecca_dev to be reflected locally.

I've tried:

git checkout rebecca_dev
git fetch dev
git merge dev
Already up to date.

When I check the online repo on Github, I expect the coding documents locally, and in the rebecca_dev remote, to match those in dev, but this is not the case. What am I doing wrong?

Upvotes: 0

Views: 820

Answers (2)

SwissCodeMen
SwissCodeMen

Reputation: 4895

This happens, when the local branch isn‘t up to date with the remote branch. So you must first bring your local branch up to date with git pull in this branch.

So first checkout dev and then git pull there. Now your local dev branch is up to date with the remote dev branch.

Then you will be able to git merge the new changes from dev into your rebecca_dev branch.

All steps summarized:

git checkout dev
git pull
git checkout rebecca_dev
git merge dev

Upvotes: 1

Karthik Nayak
Karthik Nayak

Reputation: 740

So the problem is you're making changes locally and expecting the changes to be seen on the remote branch.

So let's go line by line

git checkout rebecca_dev: This will checkout the rebecca_dev branch locally.
git fetch dev: Will fetch the remote dev changes, this is reflected locally in the origin/dev branch. (Assuming the remote is referred by origin). This will not update the local dev branch.
git merge dev: So you're merging the local dev branch to the local rebecca_dev branch. Do note you don't have the latest remote dev changes on the local dev branch.

What you'd want to do instead:

git checkout rebecca_dev
git fetch dev
git merge origin/dev
git push

The last step pushes the local changes to the remote branch to update it too.

Upvotes: 1

Related Questions