GitHub Topics (7)Tap to view
    GitHub·Version Control·Topic 4 of 7

    GitHub Forks & Open Source

    Cloning forks, linking to the original repository (Upstream), and synchronizing updates to contribute to open source projects.

    1. Forking & Upstream Synchronization

    1. git clone <fork-url>

      What it doesCopies the fork repository from your account to your local machine

      When to use itAfter forking any project on GitHub and starting to set it up locally

      Examplegit clone git@github.com:YOUR_USERNAME/PROJECT.git

    2. git remote add upstream <url>

      What it doesAdds the link to the original repository of the project as upstream for reference

      When to use itto synchronize changes coming from the original project in the future

      Examplegit remote add upstream https://github.com/ORIGINAL_OWNER/PROJECT.git

    3. git fetch upstream

      What it doesFetches all new branches and commits from the original repository without merging them

      When to use itBefore starting a new job or before synchronizing the master branch

      Examplegit fetch upstream

    4. git merge --ff-only upstream/main

      What it doesAdvance the local branch pointer to the most recent commit in the original repository without creating a commit merge

      When to use itto update the local main branch to exactly match the original repository

      Examplegit merge --ff-only upstream/main

    5. git push origin main

      What it doesUploads updates taken from the upstream to your fork repository on GitHub

      When to use itto keep the master branch in your cloud copy in sync with the original

      Examplegit push origin main

    6. git push origin feature-branch

      What it doesThe new modifications branch is uploaded to the fork in preparation for opening PR to the original project

      When to use itAfter you finish preparing a feature or fix to contribute

      Examplegit push -u origin feature-fix-type

    Offline · Reading cached copy