This question already has answers here:
Merge changes from remote github repository to your local repository
(4 answers)
Closed 7 years ago.
I have forked a repo on my github. And I also cloned my fork on my desktop like this
git clone myfork.git
and did some commits. How do I keep my fork in sync with the the original repo with my latest commits?
After you commit, you should git fetch upstream, which will get the changes from the parent repository. After this, you should git checkout master, which will move you back to your fork's master branch. The parent repository's changes are held in the upstream/master branch, so you can git merge upstream/master to merge the parent repository's changes into your current fork. This will update your repository, and repeat whenever you want to pull the latest changes from the parent repository.
As stated in the comments, you can use https://help.github.com/articles/syncing-a-fork/ for more help.
Since you already cloned the repository. Now, add your original repository, for convention lets name it original repository. Same as above, Copy-URL of your authors original repository
git remote add original COPY-URL
If you successfully added the remote repository. Now lets fetch that, we are actually pullinig the original here:
git fetch original
Since we fetched the original. Lets merge them
git merge
git merge original/master
How do I update a GitHub forked repository?
You can refer here for more details:
Related
On github, how is it possible for the owner of an original repository to pull the changes that were made in a fork by another user, without a pull request? Or anyway include the fork's changes into the original repository, maintaining information about the fork's author?
Should I clone the fork and then push it to the original repository?
Or I could copy them manually, but that wouldn't be fair at all, because the project would lose any information about the fork's changes author.
You would use the normal distributed workflow of Git here. That is, add the other repository as a second remote to your local repository, and then simply merge their changes in.
git remote add others-fork https://github.com/otheruser/fork.git
git fetch others-fork
git checkout master
git merge others-fork/master
This would merge the changes from their master into your local master. Afterwards, you can push your changes to publish their commits in your repository.
I've forked a version of this
https://github.com/googlesamples/android-topeka
a few days ago.
I'm making changes to it in Android Studio. Now changes have been committed to the original project at
https://github.com/googlesamples/android-topeka
I want to merge my changes I've been making locally with that version. But at the same time I want to keep my version private?
How can I COMPARE my changes locally with the master?
Typically, your workflow in GitHub will go something like this:
git pull origin master
# work work work
git commit -m 'I made some changes to android-topeka'
git pull origin master
# resolve merge conflicts
git push origin master
The general strategy is to commit your local changes, then git pull the remote to bring in any changes which other developers might have made to the android-topeka repository since you last pulled. Once you have resolved the merge conflicts (if any), then you can fast-forward the branch on GitHub by doing a git push.
Note that origin points to https://github.com/googlesamples/android-topeka in your case. I also assume that your local branch is called master, as I only see one master branch under the android-topeka project on GitHub.
I'm new to GitHub, but I read every possible help section and many StackOverflow posts and I still don't have the answer I'm looking for. (Btw I removed the https:// in front of the links because of lack of rep points, but in the original they are present).
There is the repository I want to sync my files with - github.com/Something/project.git
I forked it. Then I cloned my fork to my computer using Git Bash:
git clone github.com/MY_USERNAME/project.git
I opened the folder:
cd project/
I added as a second remote the repository:
git remote add upstream github.com/Something/project.git
I downloaded its files:
git fetch upstream
Now I have:
git remote -v
origin github.com/MY_USERNAME/project.git (fetch)
origin github.com/MY_USERNAME/project.git (push)
upstream github.com/Something/project.git (fetch)
upstream github.com/Something/project.git (push)
And here comes the problem. Let's say I deleted some files from my computer and from my fork. And the main repository doesn't have new updates meanwhile. I try to download original files again and to update my fork using:
git fetch upstream master
git merge upstream/master
But NOTHING updates. I get only Allready up-to-date all the time!!! I tried many different "ways" including pull. I tried to "change" the branch with checkout, but I don't have any others, so nothing happens again. There is only one branch in the original repository and only one in mine, so it's not the problem. Btw I push my files to the fork without any problem!
So the question is: What does it mean to sync the fork, when it doesn't even download. Is it possible to directly update my fork, without having to update first my local files and then upload to my fork?
It won't update because you already have every commit from upstream in your hostory. If you deleted some files and commited the changes that means you are ahead.
Im trying to make a copy of a repo I have access to. However when I fork it to my own account not all the latest changes come. For example the original has 840 commits and 7 contributors and my fork has only 733 and 4 contributors. Also the read me file is not updated.
How can I get a complete copy of all the changes/updates, etc?
(I am a newbie so I need very basic and simple instructions.)
When you fork a repository it will only include the master branch by default. If you want the other branches the easiest thing to do is clone the forked copy to your workspace then add the original repository as a new remote. I usually do the following:
git remote add upstream url-to-original-repository
git fetch --all
git branch -a
That will list all the branches and you can checkout any of the upstream branches that are interesting.
I forked a GitHub project several days ago and from its issues, I can see that the master branch has had some modifications since.
When I cd to my location directory of this project and use git pull, it says, "Already up-to-date". Why?
How do I update my fork to include the commits from the original repo?
When you fork a repository, a copy of the original repository is established on your GitHub account. This permits read+write access to the "copy".
When the original repository resource has commits that would benefit your copy, follow these steps to update your fork's master branch. You could update other branches, but typical workflow is to update master against the original repository.
Open a Terminal
cd to your project directory
git remote add upstream <url-of-original-repository>
git branch and verify you are on master branch
git pull --rebase upstream master
Step #5 will fetch all new commits of the "original" repository, apply them to master branch from the last merge-base, then include all of your branch's commits "on top".
Any time you need to update your fork again, simply run the command in step #5.