Syncing Your GitHub Fork

Поделиться
HTML-код
  • Опубликовано: 14 окт 2024
  • 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....
    Twitter: / justmarkham
    GitHub: github.com/jus...
    == LINKS RELATED TO THIS VIDEO ==
    Diagrams of forking and syncing: www.dataschool....
    Syncing a fork: help.github.co...
    Git quick reference for beginners: www.dataschool....
    == 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

  • @danielchacreton2401
    @danielchacreton2401 4 года назад +1

    Once again you prove to be probably the most valuable data science resource on RUclips. Thanks for taking the time to make these videos. I owe you a PhD.

    • @dataschool
      @dataschool  4 года назад

      Thank you very much! 🙏

  • @RedWrites
    @RedWrites 7 лет назад +1

    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 лет назад +1

      Awesome! Glad I could be of help! :)

  • @robertboothe3405
    @robertboothe3405 7 лет назад +1

    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.

  • @dataschool
    @dataschool  10 лет назад +5

    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.

  • @__nitinkumar__
    @__nitinkumar__ 3 года назад

    Somethings are made so perfectly, that they never change.

  • @camilaortega8644
    @camilaortega8644 10 лет назад +1

    Great set of videos! Easy to follow, it helped me to get started with git and github and to finished my course assignment! Thanks!

  • @rayansuryadikara9353
    @rayansuryadikara9353 4 года назад

    Thank you very much, this serial of videos is highly underrated!

  • @denisebarnes6722
    @denisebarnes6722 9 лет назад

    Extremely helpful in illustrating the difference between pull and fetch!!

    • @dataschool
      @dataschool  9 лет назад

      Denise Barnes Awesome, glad it was helpful! :)

  • @BharatSingh-zk8lx
    @BharatSingh-zk8lx 6 лет назад +2

    Finally found what I was looking for. THANKS, A LOOOOOT, trying to find this for so long

  • @grapedrank666
    @grapedrank666 3 года назад +1

    thank you best explanation i have encountered.

  • @timt6626
    @timt6626 9 лет назад +1

    Your videos are very clear and helpful, thanks!

    • @dataschool
      @dataschool  9 лет назад

      +Tim Theeboom Thanks for your kind comments!

  • @DonovanBrown
    @DonovanBrown 8 лет назад +3

    Exactly what I was looking for. Thanks.

  • @MrMattz84
    @MrMattz84 9 лет назад +1

    Thank you for this VERY CLEAR tutorial!

    • @dataschool
      @dataschool  9 лет назад

      MrMattz84 You're very welcome!

  • @Alpha777beta
    @Alpha777beta 10 лет назад +3

    Now This is Exact Explanation with diagram awesome

    • @dataschool
      @dataschool  10 лет назад

      Great! Glad it was helpful to you, Vijay!

  • @OrlandoVallejos
    @OrlandoVallejos 6 лет назад

    Great video! Easy to understand with that simple example!

  • @harshendubhardwaj5283
    @harshendubhardwaj5283 8 лет назад +1

    Great videos man, thanks a lot

  • @varadtravels503
    @varadtravels503 4 года назад +1

    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.

  • @emerson0001
    @emerson0001 5 лет назад +1

    Excellent, thanks a lot!

  • @oleholgerson3416
    @oleholgerson3416 4 года назад +1

    great explanation, thank you!

  • @SimpleLangSolution
    @SimpleLangSolution 6 лет назад

    Wow! Can't be explained any better.

    • @dataschool
      @dataschool  6 лет назад

      Glad it was helpful to you! :)

  • @JennJanesko
    @JennJanesko 7 лет назад +1

    Thanks! You got me started with github. :)

  • @denismpa
    @denismpa 8 лет назад

    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  8 лет назад

      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

  • @dyegorodrigo4759
    @dyegorodrigo4759 9 лет назад

    Very simple and instructive, Thanks ;)

    • @dataschool
      @dataschool  9 лет назад

      +Dyego Rodrigo You're welcome :)

  • @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

  • @suren6413
    @suren6413 2 года назад

    It is really helpful. Thanks a lot

  • @sagarkharade8535
    @sagarkharade8535 4 года назад +1

    Thanks buddy :)

  • @ReidKizuka
    @ReidKizuka 7 лет назад

    This youtube video is super useful, thank you soooo much!!!!

  • @excaliburzerotech9393
    @excaliburzerotech9393 9 лет назад

    Thanks! This video was very helpful.

    • @dataschool
      @dataschool  9 лет назад

      ExcaliburZeroTech You're very welcome!

  • @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

  • @ErnstJonny
    @ErnstJonny 6 лет назад

    Helped me a lot. Thanks.

  • @yassirez-znafry5882
    @yassirez-znafry5882 4 года назад +3

    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 4 года назад +1

      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

  • @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??

  • @JitenPalaparthi
    @JitenPalaparthi 4 года назад

    easy to understand... kudos

  • @MuhammadIbrahim-bq1yx
    @MuhammadIbrahim-bq1yx 5 лет назад

    U just solved my problem..... Thanks alot....!

  • @notia2000
    @notia2000 9 лет назад

    Excellent video you saved me a lot of time Thank you!!!

    • @dataschool
      @dataschool  9 лет назад

      Anton Szilasi You're very welcome!

  • @mikecmw8492
    @mikecmw8492 4 года назад

    Old but perfect

  • @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 года назад +1

      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

  • @palashrathore6277
    @palashrathore6277 3 года назад +1

    Thanks!

  • @viranirav
    @viranirav 10 лет назад +1

    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  10 лет назад

      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.

  • @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.

  • @leighabrown2992
    @leighabrown2992 5 лет назад

    This video helped me so much!!!!! Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @richsajdak
    @richsajdak 6 лет назад

    What is the advantage of doing a fetch and then merge rather then a single pull command?

  • @tomay3000
    @tomay3000 6 лет назад

    Well done, well explained ;)

  • @chenhanhan8950
    @chenhanhan8950 6 лет назад

    Excellent!!!! Thanks

  • @ariel_alves_dutra
    @ariel_alves_dutra 4 года назад

    Thank you!

  • @rishilrk2205
    @rishilrk2205 5 лет назад

    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  5 лет назад +1

      I think it's the SSH passphrase, but I actually can't remember!

  • @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.

  • @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: ruclips.net/p/PL5-da3qGB5IBLMp7LtN8Nc3Efd4hJq0kD
      Good luck!

  • @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!

  • @siniarskimar
    @siniarskimar 7 лет назад

    fatal: refusing to merge unrelated histories
    feched fork is added as remote.
    tried to checkout --track but master branch exists

    • @dataschool
      @dataschool  7 лет назад

      Sorry, it's hard to troubleshoot git errors remotely, good luck!

  • @akshay231990
    @akshay231990 7 лет назад

    thanks

  • @purson5352
    @purson5352 6 лет назад

    You can use my shell script to synchronize, welcome everyone to correct. github.com/pursonchen/sync-fork.git

  • @ashimagarg7259
    @ashimagarg7259 6 лет назад

    Thanks !