Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git branch --set-upstream-to origin/master master
    ```

    6. Push to your fork via your "origin" remote (the word `origin` should be able to be omitted [ie: just write `git push`] if you did Step 4).
    6. Push to your fork via your "origin" remote (the word `origin` should be able to be omitted (ie: just write `git push`) if you did Step 4).

    ```bash
    git push origin
  2. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git branch --set-upstream-to origin/master master
    ```

    6. Push to your fork via your "origin" remote (`origin` should be able to be omitted if you did Step 4).
    6. Push to your fork via your "origin" remote (the word `origin` should be able to be omitted [ie: just write `git push`] if you did Step 4).

    ```bash
    git push origin
  3. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,14 @@ If you are like me you find yourself cloning a repo, making some proposed change

    To follow GitHub flow you should really have created a fork initially as a public representation of the forked repository and the clone that instead. My understanding is that the typical setup would have your local repository pointing to your fork as **origin** and the original forked repository as **upstream** so that you can use these keywords in other git commands.

    1. Clone some repo (you've probably already done this step)
    1. Clone some repo (you've probably already done this step).

    ```bash
    git clone git@github...some-repo.git
    ```

    2. Manually [fork their repo](https://guides.github.com/activities/forking/) via the Github website directly.
    3. In your local system, rename your **origin** remote to **upstream**
    3. In your local system, rename your **origin** remote to **upstream**.

    ```bash
    git remote rename origin upstream
    @@ -21,7 +21,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git remote add origin git@github...my-fork
    ```

    4. Fetch from new origin
    4. Fetch from new origin.

    ```bash
    git fetch origin
    @@ -35,7 +35,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git branch --set-upstream-to origin/master master
    ```

    6. Push to fork (origin should be able to omitted given step 4)
    6. Push to your fork via your "origin" remote (`origin` should be able to be omitted if you did Step 4).

    ```bash
    git push origin
  4. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git fetch origin
    ```

    5. Make local branch "master" track remote branch "origin/master" (ie: remote branch "master" from remote "origin" you just set above). See more syntax examples here: https://stackoverflow.com/a/2286030/4561887.
    5. Make local branch "master" track remote branch "origin/master" (ie: remote branch "master" from remote "origin" which you just set above). See more syntax examples here: https://stackoverflow.com/a/2286030/4561887.

    ~~`git branch --set-upstream master origin/master`~~ (deprecated)

  5. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git fetch origin
    ```

    5. Make local branch "master" track remote branch "origin/master" (ie: remote branch "master" from remote "origin"). See more syntax examples here: https://stackoverflow.com/a/2286030/4561887.
    5. Make local branch "master" track remote branch "origin/master" (ie: remote branch "master" from remote "origin" you just set above). See more syntax examples here: https://stackoverflow.com/a/2286030/4561887.

    ~~`git branch --set-upstream master origin/master`~~ (deprecated)

  6. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git remote rename origin upstream
    ```

    3. Add a new origin which now points to your fork you just made above, instead of to to the original repository.
    3. Add a new origin which now points to your fork you just made above (instead of to to the original repository).

    ```bash
    git remote add origin git@github...my-fork
  7. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git remote rename origin upstream
    ```

    3. Add a new origin
    3. Add a new origin which now points to your fork you just made above, instead of to to the original repository.

    ```bash
    git remote add origin git@github...my-fork
  8. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -27,8 +27,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git fetch origin
    ```

    5. Make local branch "master" track remote branch "origin/master" (ie: remote branch "master" from remote "origin"):
    - See more syntax examples here: https://stackoverflow.com/a/2286030/4561887
    5. Make local branch "master" track remote branch "origin/master" (ie: remote branch "master" from remote "origin"). See more syntax examples here: https://stackoverflow.com/a/2286030/4561887.

    ~~`git branch --set-upstream master origin/master`~~ (deprecated)

  9. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    ```

    2. Manually [fork their repo](https://guides.github.com/activities/forking/) via the Github website directly.
    3. In your local, rename your **origin** remote to **upstream**
    3. In your local system, rename your **origin** remote to **upstream**

    ```bash
    git remote rename origin upstream
  10. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git clone git@github...some-repo.git
    ```

    2. Manually fork their repo via the [Github website](https://guides.github.com/activities/forking/) directly.
    2. Manually [fork their repo](https://guides.github.com/activities/forking/) via the Github website directly.
    3. In your local, rename your **origin** remote to **upstream**

    ```bash
  11. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git clone git@github...some-repo.git
    ```

    2. Fork their repo on [Github](https://guides.github.com/activities/forking/)
    2. Manually fork their repo via the [Github website](https://guides.github.com/activities/forking/) directly.
    3. In your local, rename your **origin** remote to **upstream**

    ```bash
  12. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,8 @@ To follow GitHub flow you should really have created a fork initially as a publi
    git fetch origin
    ```

    5. Set origin master
    5. Make local branch "master" track remote branch "origin/master" (ie: remote branch "master" from remote "origin"):
    - See more syntax examples here: https://stackoverflow.com/a/2286030/4561887

    ~~`git branch --set-upstream master origin/master`~~ (deprecated)

  13. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ To follow GitHub flow you should really have created a fork initially as a publi

    5. Set origin master

    ~~`git branch --set-upstream master origin/master`~~ #deprecated
    ~~`git branch --set-upstream master origin/master`~~ (deprecated)

    ```bash
    git branch --set-upstream-to origin/master master
  14. ElectricRCAircraftGuy revised this gist Jan 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ To follow GitHub flow you should really have created a fork initially as a publi

    5. Set origin master

    ~~`git branch --set-upstream master origin/master`~~
    ~~`git branch --set-upstream master origin/master`~~ #deprecated

    ```bash
    git branch --set-upstream-to origin/master master
  15. @jpierson jpierson revised this gist Mar 15, 2017. 1 changed file with 12 additions and 5 deletions.
    17 changes: 12 additions & 5 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -20,16 +20,23 @@ To follow GitHub flow you should really have created a fork initially as a publi
    ```bash
    git remote add origin git@github...my-fork
    ```
    4. Set origin master

    4. Fetch from new origin

    ```bash
    git branch --set-upstream master origin/master
    git fetch origin
    ```

    5. Set origin master

    5. Fetch & push (origin should be able to omitted given step 4)
    ~~`git branch --set-upstream master origin/master`~~

    ```bash
    git branch --set-upstream-to origin/master master
    ```
    git fetch origin

    6. Push to fork (origin should be able to omitted given step 4)

    ```bash
    git push origin
    ```
  16. @jpierson jpierson revised this gist Mar 13, 2017. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ To follow GitHub flow you should really have created a fork initially as a publi

    5. Fetch & push (origin should be able to omitted given step 4)

    ```
    git fetch origin
    git push origin
    ```
    ```
    git fetch origin
    git push origin
    ```
  17. @jpierson jpierson revised this gist Mar 13, 2017. 1 changed file with 12 additions and 10 deletions.
    22 changes: 12 additions & 10 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -11,23 +11,25 @@ To follow GitHub flow you should really have created a fork initially as a publi
    2. Fork their repo on [Github](https://guides.github.com/activities/forking/)
    3. In your local, rename your **origin** remote to **upstream**

    ```bash
    git remote rename origin upstream
    ```
    ```bash
    git remote rename origin upstream
    ```

    3. Add a new origin

    ```bash
    git remote add origin git@github...my-fork
    ```
    ```bash
    git remote add origin git@github...my-fork
    ```

    4. Set origin master

    ```bash
    git branch --set-upstream master origin/master
    ```
    ```bash
    git branch --set-upstream master origin/master
    ```

    5. Fetch & push (origin should be able to omitted given step 4)

    ```
    git fetch origin
    git push origin
    git push origin
    ```
  18. @jpierson jpierson revised this gist Mar 13, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@ To follow GitHub flow you should really have created a fork initially as a publi

    1. Clone some repo (you've probably already done this step)

    ```bash
    git clone git@github...some-repo.git
    ```
    ```bash
    git clone git@github...some-repo.git
    ```

    2. Fork their repo on [Github](https://guides.github.com/activities/forking/)
    3. In your local, rename your **origin** remote to **upstream**
  19. @jpierson jpierson revised this gist Mar 13, 2017. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,6 @@ If you are like me you find yourself cloning a repo, making some proposed change

    To follow GitHub flow you should really have created a fork initially as a public representation of the forked repository and the clone that instead. My understanding is that the typical setup would have your local repository pointing to your fork as **origin** and the original forked repository as **upstream** so that you can use these keywords in other git commands.

    * Off the top of my head *

    1. Clone some repo (you've probably already done this step)

    ```bash
  20. @jpierson jpierson revised this gist Mar 13, 2017. 2 changed files with 35 additions and 28 deletions.
    28 changes: 0 additions & 28 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,28 +0,0 @@
    So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!

    Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.

    * Off the top of my head *

    1. Fork their repo on Github
    2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it

    git remote add my-fork git@github...my-fork.git
    git fetch my-fork
    git push my-fork

    Otherwise, if you want to follow convention:

    1. Fork their repo on Github
    2. In your local, rename your origin remote to upstream

    git remote rename origin upstream

    3. Add a new origin

    git remote add origin git@github...my-fork

    4. Fetch & push

    git fetch origin
    git push origin
    35 changes: 35 additions & 0 deletions switch-local-git-repo-to-fork.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    If you are like me you find yourself cloning a repo, making some proposed changes and then deciding to later contributing back using the [GitHub Flow](https://guides.github.com/introduction/flow/) convention. Below is a set of instructions I've developed for myself on how to deal with this scenario and an explanation of why it matters based on [jagregory's gist](https://gist.github.com/jagregory/710671).

    To follow GitHub flow you should really have created a fork initially as a public representation of the forked repository and the clone that instead. My understanding is that the typical setup would have your local repository pointing to your fork as **origin** and the original forked repository as **upstream** so that you can use these keywords in other git commands.

    * Off the top of my head *

    1. Clone some repo (you've probably already done this step)

    ```bash
    git clone git@github...some-repo.git
    ```

    2. Fork their repo on [Github](https://guides.github.com/activities/forking/)
    3. In your local, rename your **origin** remote to **upstream**

    ```bash
    git remote rename origin upstream
    ```

    3. Add a new origin

    ```bash
    git remote add origin git@github...my-fork
    ```

    4. Set origin master

    ```bash
    git branch --set-upstream master origin/master
    ```

    5. Fetch & push (origin should be able to omitted given step 4)

    git fetch origin
    git push origin
  21. @jagregory jagregory created this gist Nov 22, 2010.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!

    Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.

    * Off the top of my head *

    1. Fork their repo on Github
    2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it

    git remote add my-fork git@github...my-fork.git
    git fetch my-fork
    git push my-fork

    Otherwise, if you want to follow convention:

    1. Fork their repo on Github
    2. In your local, rename your origin remote to upstream

    git remote rename origin upstream

    3. Add a new origin

    git remote add origin git@github...my-fork

    4. Fetch & push

    git fetch origin
    git push origin