Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge changes from remote github repository to your local repository

I have forked a repository on github some time ago, made a small change and pushed the change back to my github fork. The original repository has changed since. I would like to merge the changes from the original repository to my fork.

I am new to both git and github, and I need specific commands how to do it.

like image 674
Željko Filipin Avatar asked May 15 '09 09:05

Željko Filipin


People also ask

How do you merge changes from a remote repo?

Simply add original repo as a remote and merge your fork with it; then push merged fork to github. There's also a ruby gem for easier github operations.

How do I pull changes from remote to local repository?

Fetching changes from a remote repositoryUse git fetch to retrieve new work done by other people. Fetching from a repository grabs all the new remote-tracking branches and tags without merging those changes into your own branches. Otherwise, you can always add a new remote and then fetch.

How do I merge local and remote branch changes?

Merge a Remote Branch to a Local Branch in Git by Tracking and Pulling Changes on the Remote Repository. We will now clone a remote repository containing two branches, master and gh-pages . Then, we will create a local branch another-branch and set it to track any and pull changes made on the remote main branch.


4 Answers

git remote add {name} {Public Clone URL}
git pull {name} master
git push

Example:

git remote add bret git://github.com/bret/watir.git
git pull bret master
git push
like image 176
Željko Filipin Avatar answered Oct 15 '22 16:10

Željko Filipin


git pull origin master

will do the job creating additional merge commit. If you do not have conflicts and do not want to create a rejoin (with additional 'merge' commit) for every commit that you push then rebase is more preferred. You can do it with the Git Gui+gitk. Just fetch remote with Git Gui then open history with gitk and create temporary r_master branch at remotes/origin/master fetched. Finally, call git rebase r_master in the git bash. This will place your commits on top of the remote modifications. You are ready to push and remove the r_master.

This comment suggests that there are shortcuts for this flow.

like image 35
Val Avatar answered Oct 15 '22 15:10

Val


Simply add original repo as a remote and merge your fork with it; then push merged fork to github.

There's also a ruby gem for easier github operations. You can merge upstream with one call...

like image 25
Marcin Gil Avatar answered Oct 15 '22 17:10

Marcin Gil


Syncing a fork

(from GitHub Help)

https://help.github.com/articles/syncing-a-fork

like image 28
fat Avatar answered Oct 15 '22 17:10

fat