Syncing Your GitHub Fork

  Рет қаралды 109,460

Data School

Data School

10 жыл бұрын

This is video #9 in the Data School series, "Introduction to Git and GitHub." Relevant links, a command list, and the full transcript are below. Playlist: • Version control with G...
== LET'S CONNECT! ==
Blog: www.dataschool.io
Newsletter: www.dataschool.io/subscribe/
Twitter: / justmarkham
GitHub: github.com/justmarkham
== LINKS RELATED TO THIS VIDEO ==
Diagrams of forking and syncing: www.dataschool.io/simple-guide...
Syncing a fork: help.github.com/articles/sync...
Git quick reference for beginners: www.dataschool.io/git-quick-re...
== COMMAND LIST ==
show your remotes: git remote -v
add an upstream remote: git remote add upstream [URL]
fetch changes from the upstream: git fetch upstream
merge those changes into your repo: git merge upstream/master
push those changes to the origin: git push origin master
== TRANSCRIPT ==
In this video, we're going to talk about syncing your fork, what that means, and why you might want to do it.
To start, let's go through what we already know about forks. Here's a diagram from my blog, and I'll link to this in the video description. In this diagram, the top level is the GitHub level, and the bottom level is your local computer.
Remember that if you want to copy a GitHub repo, you just fork it, and then you can clone it to your local computer. After making changes and committing those changes, you can push the changes back up to GitHub. We won't cover pull requests in this video, but that's simply how you ask the owner of the original repo to pull your changes into their repo.
Anyway, let's pretend that you forked a repo yesterday, and then today, the repo owner made some changes that you want to incorporate into your fork. Remember from a previous video that forks do not automatically stay in sync, and thus you have to do this manually.
Let's look at another diagram. If you want to sync your fork with the original repo, which we call the "upstream", this actually happens through your local computer. You simply "fetch" the changes from the upstream, you "merge" them into your repo, and then you "push" them up to GitHub. Note that the "fetch" and "merge" steps are often combined into a single step called a "pull", but it's generally recommended that you fetch and merge in two separate steps.
Let's actually do this for one of my repos. Here's the commit history of a repo that I forked, and here's the commit history of my fork. You can see that the original repo has one additional commit since I forked it. I've opened Git Bash, and we're already in the working directory for that repo.
First, let's check our remotes with "git remote -v". We've got an "origin" remote, but we also need an "upstream" remote that points to the original repo. We'll copy the URL from GitHub. You'll probably be using the HTTPS URL, but I set up SSH so I'm using the SSH URL. Then we "git remote add upstream" and paste the URL using the "Insert" key on Windows. Let's check that it worked.
Now we're ready to fetch. You type "git fetch upstream", and then type your password. That command fetched the changes, and stored them in a branch called "upstream/master". You can actually switch to that branch and look at the changes if you like, but we're going to go ahead and merge those changes. You type "git merge upstream/master", which tells git to merge that branch into your working branch, which also happens to be called "master".
If you like, you can also push those changes up to GitHub, so that your GitHub repo is in sync. Just like before, we type "git push origin master", then your password, and you're done! You can see that the change is now in my repo.

Пікірлер: 107
@camilaortega8644
@camilaortega8644 10 жыл бұрын
Great set of videos! Easy to follow, it helped me to get started with git and github and to finished my course assignment! Thanks!
@RedWrites
@RedWrites 7 жыл бұрын
Thank you so much for this, I have been looking for weeks for how to do this. So many of the others were so confusing, this was clear and clean. Thanks again!
@dataschool
@dataschool 7 жыл бұрын
Awesome! Glad I could be of help! :)
@rayansuryadikara9353
@rayansuryadikara9353 4 жыл бұрын
Thank you very much, this serial of videos is highly underrated!
@BharatSingh-zk8lx
@BharatSingh-zk8lx 6 жыл бұрын
Finally found what I was looking for. THANKS, A LOOOOOT, trying to find this for so long
@dataschool
@dataschool 6 жыл бұрын
Great to hear!
@danielchacreton2401
@danielchacreton2401 3 жыл бұрын
Once again you prove to be probably the most valuable data science resource on KZfaq. Thanks for taking the time to make these videos. I owe you a PhD.
@dataschool
@dataschool 3 жыл бұрын
Thank you very much! 🙏
@grapedrank666
@grapedrank666 2 жыл бұрын
thank you best explanation i have encountered.
@dataschool
@dataschool 2 жыл бұрын
Thank you! 🙏
@__nitinkumar__
@__nitinkumar__ 2 жыл бұрын
Somethings are made so perfectly, that they never change.
@dataschool
@dataschool 2 жыл бұрын
🙏
@DonovanBrown
@DonovanBrown 8 жыл бұрын
Exactly what I was looking for. Thanks.
@dataschool
@dataschool 8 жыл бұрын
Great to hear!
@timt6626
@timt6626 8 жыл бұрын
Your videos are very clear and helpful, thanks!
@dataschool
@dataschool 8 жыл бұрын
+Tim Theeboom Thanks for your kind comments!
@denisebarnes6722
@denisebarnes6722 9 жыл бұрын
Extremely helpful in illustrating the difference between pull and fetch!!
@dataschool
@dataschool 9 жыл бұрын
Denise Barnes Awesome, glad it was helpful! :)
@MrMattz84
@MrMattz84 9 жыл бұрын
Thank you for this VERY CLEAR tutorial!
@dataschool
@dataschool 9 жыл бұрын
MrMattz84 You're very welcome!
@dataschool
@dataschool 10 жыл бұрын
Alberto, I don't know of any way to sync your fork to the upstream without having to use a local repo in-between. Regarding changes you make to your fork: they will get preserved when you merge in changes from the upstream, unless those changes conflict with one another. In that case, git will ask you to manually fix any merge conflicts, and you will have to decide which changes to keep.
@robertboothe3405
@robertboothe3405 7 жыл бұрын
Really appreciate your videos on git & github. Very clear. Wish you would do one on branches with git/github though
@dataschool
@dataschool 7 жыл бұрын
Thanks for your kind words! I'll take your suggestion under consideration.
@OrlandoVallejos
@OrlandoVallejos 6 жыл бұрын
Great video! Easy to understand with that simple example!
@dataschool
@dataschool 6 жыл бұрын
Thanks!
@JennJanesko
@JennJanesko 7 жыл бұрын
Thanks! You got me started with github. :)
@dataschool
@dataschool 7 жыл бұрын
Great to hear! :)
@notia2000
@notia2000 9 жыл бұрын
Excellent video you saved me a lot of time Thank you!!!
@dataschool
@dataschool 9 жыл бұрын
Anton Szilasi You're very welcome!
@excaliburzerotech9393
@excaliburzerotech9393 9 жыл бұрын
Thanks! This video was very helpful.
@dataschool
@dataschool 9 жыл бұрын
ExcaliburZeroTech You're very welcome!
@harshendubhardwaj5283
@harshendubhardwaj5283 8 жыл бұрын
Great videos man, thanks a lot
@dataschool
@dataschool 8 жыл бұрын
+H1B1 You're welcome!
@dyegorodrigo4759
@dyegorodrigo4759 8 жыл бұрын
Very simple and instructive, Thanks ;)
@dataschool
@dataschool 8 жыл бұрын
+Dyego Rodrigo You're welcome :)
@Alpha777beta
@Alpha777beta 9 жыл бұрын
Now This is Exact Explanation with diagram awesome
@dataschool
@dataschool 9 жыл бұрын
Great! Glad it was helpful to you, Vijay!
@kazukikimoto8322
@kazukikimoto8322 7 жыл бұрын
This youtube video is super useful, thank you soooo much!!!!
@dataschool
@dataschool 7 жыл бұрын
You're very welcome!
@suren6413
@suren6413 2 жыл бұрын
It is really helpful. Thanks a lot
@dataschool
@dataschool 2 жыл бұрын
Glad it was helpful!
@ErnstJonny
@ErnstJonny 5 жыл бұрын
Helped me a lot. Thanks.
@dataschool
@dataschool 5 жыл бұрын
You're welcome!
@oleholgerson3416
@oleholgerson3416 4 жыл бұрын
great explanation, thank you!
@dataschool
@dataschool 4 жыл бұрын
You're welcome!
@emerson0001
@emerson0001 4 жыл бұрын
Excellent, thanks a lot!
@dataschool
@dataschool 4 жыл бұрын
Thank you!
@JitenPalaparthi
@JitenPalaparthi 4 жыл бұрын
easy to understand... kudos
@dataschool
@dataschool 4 жыл бұрын
Thank you!
@SimpleLangSolution
@SimpleLangSolution 6 жыл бұрын
Wow! Can't be explained any better.
@dataschool
@dataschool 6 жыл бұрын
Glad it was helpful to you! :)
@MuhammadIbrahim-bq1yx
@MuhammadIbrahim-bq1yx 4 жыл бұрын
U just solved my problem..... Thanks alot....!
@dataschool
@dataschool 4 жыл бұрын
Great to hear!
@leighabrown2992
@leighabrown2992 5 жыл бұрын
This video helped me so much!!!!! Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@dataschool
@dataschool 5 жыл бұрын
You're very welcome! :)
@ariel_alves_dutra
@ariel_alves_dutra 3 жыл бұрын
Thank you!
@dataschool
@dataschool 3 жыл бұрын
You're welcome!
@chenhanhan8950
@chenhanhan8950 6 жыл бұрын
Excellent!!!! Thanks
@dataschool
@dataschool 6 жыл бұрын
You're welcome!
@mikecmw8492
@mikecmw8492 4 жыл бұрын
Old but perfect
@tomay3000
@tomay3000 6 жыл бұрын
Well done, well explained ;)
@dataschool
@dataschool 6 жыл бұрын
Thanks!
@palashrathore6277
@palashrathore6277 3 жыл бұрын
Thanks!
@dataschool
@dataschool 3 жыл бұрын
Welcome!
@sagarkharade8535
@sagarkharade8535 3 жыл бұрын
Thanks buddy :)
@dataschool
@dataschool 3 жыл бұрын
No problem 👍
@varadtravels503
@varadtravels503 4 жыл бұрын
How to merge only selected files from upstream? Here's the scenario: I forked a repo and working on my own customization while original project is independantly developing other features. Now I wish to add few newly added files from master (original repo) which were not present at the time of my fork. I do not with to merge their other files, which I have already modified as per my requirement.
@AlbertoMarioStriedingerPinilla
@AlbertoMarioStriedingerPinilla 10 жыл бұрын
Is there a way to sync from the upstream repo to my GitHub repo without having to use my local repo in-between. This is in case I happen not to be in my computer, like in a library computer from my university...?... Also , the changes that you made on you fork are also merged, correct ? I mean, you dont lose your "new"information or changes done to your fork in the process, correct ?. =) Thanks in advance
@aquibjaved3911
@aquibjaved3911 7 жыл бұрын
Great video, I have a question. If we assume that before fetching from upstream, some of the files in our local repo was changed. In that case, is fetch/merge going to cause a conflict? For instance, I cloned a forked repo, then made some changes in my local repo, and now I want to sync the fork. But since my local repo has some files that are changed from the one I'm fetching from, shouldn't there be conflicts? What should be done in that scenario?
@dataschool
@dataschool 7 жыл бұрын
That's right, you might have a merge conflict in that case. Here are some tips for how to resolve it: stackoverflow.com/questions/161813/how-to-resolve-merge-conflicts-in-git
@denismpa
@denismpa 7 жыл бұрын
Hi @Data School, How could I see the changes fetched before merging them? Can I see like a diff ? Thank you very much. Awesome video.
@dataschool
@dataschool 7 жыл бұрын
Thanks! You can definitely do that, though I can't remember how at the moment :) I'm sure it's covered in Pro Git, which is an excellent Git reference: git-scm.com/book/en/v2
@akshay231990
@akshay231990 7 жыл бұрын
thanks
@dataschool
@dataschool 7 жыл бұрын
You're very welcome!
@anandhu5082
@anandhu5082 3 жыл бұрын
once we do the git fecth upstream, i dont see the branch listed in git branch,, but it is listed in git branch -r.. What is the difference between both??
@yassirez-znafry5882
@yassirez-znafry5882 4 жыл бұрын
after i type: git merge upstream/master . i get: Already up to date . even tho there are some new changes in the project. ???
@marisolnavarro6307
@marisolnavarro6307 3 жыл бұрын
You should check that you are really in master and not in some other branch. If you are working in other branch switch to master with: git checkout master
@viranirav
@viranirav 9 жыл бұрын
Hello Kevin, #1 $git merge upstream/master #2 git push origin master After #1 to merge the changes to local master, why is there no need to commit the changes local similar to adding/editing files. Why is #2 be successful to upload changed to github.
@dataschool
@dataschool 9 жыл бұрын
viranirav Great question. Because there was no divergent work to merge together, the merge operation does not involve a commit. If that was not the case, a commit would have been required.
@michaelshoemaker5635
@michaelshoemaker5635 4 жыл бұрын
Thank you for the video. I have tried this several times now, but my fork on github still states "This branch is 2 commits ahead" Is there anyway to make sure it is even with the original repo?
@dataschool
@dataschool 4 жыл бұрын
Hard to say, sorry!
@michaelshoemaker5635
@michaelshoemaker5635 4 жыл бұрын
@@dataschool No worries. Figured it out. I had to "Rebase" to get the "n commits ahead" message to go away. In case anyone runs into this as well the steps to resolve are 1) git remote add upstream 2) git fetch upstream 3) git rebase upstream/master 4) git push origin master --force
@richsajdak
@richsajdak 5 жыл бұрын
What is the advantage of doing a fetch and then merge rather then a single pull command?
@dataschool
@dataschool 5 жыл бұрын
No great advantage.
@msr4668
@msr4668 8 жыл бұрын
after the fetch and merge, does the previous PR and branches will be there ??
@dataschool
@dataschool 8 жыл бұрын
+Shekhar Reddy Mittapelly I'm sorry, I don't understand what you mean by "previous PR (pull requests) and branches". Could you explain?
@msr4668
@msr4668 8 жыл бұрын
+Data School eg: I have 3 branches made out of the previous master and there are Pull requests which are not yet got merged. If I do fetch and merge as you explained in the video, do the branches and PR exists??
@msr4668
@msr4668 8 жыл бұрын
+Data School By the way, could you please make a video explaining PULL command :-)
@dataschool
@dataschool 8 жыл бұрын
+Shekhar Reddy Mittapelly Regarding branches, you specify the branch you want to fetch from the upstream, and it merges into your working branch locally. So if you have three branches, you will have to work with them individually. Regarding pull requests, those are stored on GitHub only and are not affected by fetching and merging.
@trihuynh9825
@trihuynh9825 9 жыл бұрын
Thanks but it will only sync the master branch of my fork. How can I sync ALL its branches?
@dataschool
@dataschool 9 жыл бұрын
PHAT HUYNH You have to sync each one individually.
@MohitGupta-hy8er
@MohitGupta-hy8er 6 жыл бұрын
Help! When i type "git fetch upstream",i don't get the password option. My terminal simply goes blank.
@dataschool
@dataschool 6 жыл бұрын
I'm sorry, it's hard to troubleshoot git issues from afar. Good luck!
@rishilrk2205
@rishilrk2205 4 жыл бұрын
When it asks for passcode in gitbash what does it mean is it GitHub account passcode or admin passcode or the ssh passcode?
@dataschool
@dataschool 4 жыл бұрын
I think it's the SSH passphrase, but I actually can't remember!
@muhammadsarimmehdi
@muhammadsarimmehdi 3 жыл бұрын
this doesn't work anymore! I get the error: error: Merging is not possible because you have unmerged files. hint: Fix them up in the work tree, and then use 'git add/rm ' hint: as appropriate to mark resolution and make a commit. fatal: Exiting because of an unresolved conflict. Please make a new tutorial
@dataschool
@dataschool 3 жыл бұрын
If you follow the exact steps in the series, I promise that it will still work! Here's the series: kzfaq.info/sun/PL5-da3qGB5IBLMp7LtN8Nc3Efd4hJq0kD Good luck!
@purson5352
@purson5352 6 жыл бұрын
You can use my shell script to synchronize, welcome everyone to correct. github.com/pursonchen/sync-fork.git
@dataschool
@dataschool 6 жыл бұрын
Thanks for sharing!
@siniarskimar
@siniarskimar 6 жыл бұрын
fatal: refusing to merge unrelated histories feched fork is added as remote. tried to checkout --track but master branch exists
@dataschool
@dataschool 6 жыл бұрын
Sorry, it's hard to troubleshoot git errors remotely, good luck!
@ashimagarg7259
@ashimagarg7259 6 жыл бұрын
Thanks !
@dataschool
@dataschool 6 жыл бұрын
You're welcome!
Additional Resources for Learning Git and GitHub
1:31
Data School
Рет қаралды 19 М.
Git Fork vs. Git Clone: What's the Difference?
9:41
Eye on Tech
Рет қаралды 73 М.
Я нашел кто меня пранкует!
00:51
Аришнев
Рет қаралды 4,7 МЛН
Incredible magic 🤯✨
00:53
America's Got Talent
Рет қаралды 75 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 51 МЛН
git good with Chris! - real example: syncing a fork to upstream
14:31
Troubleshooting: Updates Rejected When Pushing to GitHub
8:57
Data School
Рет қаралды 82 М.
Git MERGE vs REBASE: The Definitive Guide
9:39
The Modern Coder
Рет қаралды 91 М.
Committing Changes in Git and Pushing to a GitHub Repository
5:32
Data School
Рет қаралды 393 М.
GitHub Forks and Pull Requests | Step by Step
12:23
Wes Doyle
Рет қаралды 76 М.
Git vs. GitHub: What's the difference?
10:06
IBM Technology
Рет қаралды 381 М.
Why do we Fork on GitHub?
3:31
Dev Leonardo
Рет қаралды 4 М.
Я нашел кто меня пранкует!
00:51
Аришнев
Рет қаралды 4,7 МЛН