Skip to content

Instantly share code, notes, and snippets.

@discdiver
Last active October 1, 2021 20:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save discdiver/04e20721aafd0d993a8bcb14b029de44 to your computer and use it in GitHub Desktop.
Save discdiver/04e20721aafd0d993a8bcb14b029de44 to your computer and use it in GitHub Desktop.
Forking, Cloning, and Syncing with Git and GitHub

How to fork, clone, and sync from a GitHub repository.

  1. From the GitHub GUI: Fork the repository (click fork).
  2. From your forked repository in the GitHub GUI: Click clone and copy the URL.
  3. From the command line: in the directory you want to put your local copy of the repository, type git status to make sure you are not already in a local git repository folder.
  4. Then type git clone insert_the_url_from_above
  5. cd into the cloned repository.
  6. git remote -v to see the tracking versions. You should see origin, but no upstream.
  7. From the original repository in the GitHub GUI (not yours): Click clone and copy the URL.
  8. git remote add upstream insert_url_of_original_repository_from_the_step_above - the URL to insert will NOT have your username in it.
  9. git remote -v to verify you have the origin and upstream repositories set correctly.
  10. Rename any files (Jupyter notebooks) you will be editing that you want to save a copy of. This will prevent issues when you pull down changes after class.
  11. Do some work and save your changes locally and to your own GitHub repository with git add my_file, git commit -m "my_msg", git push origin master.
  12. git fetch upstream master to get changes from the upstream remote class repository. You should now have any changes from the upstream repo on your local machine.
  13. git merge upstream/master to merge the changes from from upstream into your local mater branch.

Bonus:

Assuming you have installed Visual Studio Code, I suggust you set it as your default editor when git decides you need to do some editing. From the command line run git config --global core.editor "code -w".

Double bonus:

If you haven't set VSCode to be your git editor, you might get stuck in vim. To get out of vim:

  1. Press i to enter insert mode
  2. Type your message
  3. Press the Esc key
  4. Enter :x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment