- 1. Create a GitHub repository, link it to your computer, push your local changes to your GitHub repository.
- 2. Fork a repository so you can work on your own copy.
- 3. Create a "Pull Request" so your changes can be added to the original project.
- Sign in to GitHub: https://github.com/
- On the right side of the page, click on the
New repositorybutton. - Give your repository any name you like and make sure that the repository is public.
- You can go ahead and check the option to initialize the repository with a README.md file.
- Create a folder in the place you keep material for this class called
myProject. - Go into that folder.
- Create a file called
myName.txtand add your name to that file.- Windows open command line: https://www.youtube.com/watch?v=2KOFRYDMv4A&list=PLYmfkjWhXgi6bdFbdOpXIpW1LQuFOgCkQ&index=3
- Windows navigate directories from command line: https://www.youtube.com/watch?v=rfgH2lN6MzE&list=PLYmfkjWhXgi6bdFbdOpXIpW1LQuFOgCkQ&index=4
- Windows create empty file from command line: https://www.youtube.com/watch?v=rd2O_Kr3GGI
- Mac open a terminal window: https://www.youtube.com/watch?v=QROX039ckO8
- Mac navigate directories from terminal windows: https://www.youtube.com/watch?v=j6vKLJxAKfw
- Mac create empty file from command line: https://www.youtube.com/watch?v=P2iDTBsh4ho or https://www.youtube.com/watch?v=RWLT_9l76Bc or https://www.youtube.com/watch?v=J1goN2FVoIo
- Save the file and open a terminal window.
- In your terminal window,
cdto yourmyProjectfolder. - Run
git init. (Initializes your folder for tracking changes with git.) - Go to your new repository on GitHub and copy the address shown when you click the 'Clone or download' button. (Instead it may be the address in the Quick setup window. The address should be the same either way. It should look something like https://github.com/yourusername/yourrepositoryname.git .)
- Run
git remote add origin [Repository URL goes here]. (This stores the address for your GitHub repository with your local repository.)- (If you DID initialize your repository with a README, you must do a
git pull origin main --allow-unrelated-historiesfirst - to get the README file on your computer - before you'll be able to push.)
- (If you DID initialize your repository with a README, you must do a
2021 update: GitHub has changed the default name for the main repository from "master" to "main". I'm trying to replace all instances of "master" with "main" in instructions for this course. If I miss any, use the word "main" instead of "master". It's possible you'll see older screen shots with old terminology. There may be some errors with these changes. Here's a resource on StackOverflow which explains some of it. https://stackoverflow.com/questions/65173291/git-push-error-src-refspec-main-does-not-match-any-on-linux
- Open a terminal window and make sure it is in the directory of
myProject. - Run
git add nameOfMyFile.fileExtension. (This tells git you want to track changes on that file and adds it to the staging area.) or you can rungit add .to add all files. - Run
git status. (This will show what has changed in git.) - Run
git diff. (This shows what code has changed in the file.) - Run
git commit -m "The sentence I want associated with this commit message". (This prepares the changes to be pushed to GitHub and logs the message you specify.) - Run
git push origin main(Your code is now pushed to GitHub. Be sure to includeorigin main, as this tells GitHub which branch you want to push to, and creates the branch if it doesn't exist yet.) If you get an error, it could be because thegit initstatement you ran earlier gave your repository the default name of "master". You can rename your local repository by running the commandgit branch -m master mainthen try the commandgit push -u origin main - Go to your repository on GitHub and see your updates.

- (You can also see the pdf instruction sheets with screenshots included in this repository.)
Here's a short summary of the steps to successfully clone your repository. If you encounter a problem check if you missed any of these steps.
- Sign in to GitHub
- Create a new repository with a README.md file
- Create a folder on your computer where you want to put this assignment. (I called mine createTest)
- Create a file in that folder called myName.txt
- Open a terminal in that folder
- git init
- Copy the address for your repository on GitHub
- git remote add origin [Repository URL goes here]
- git pull origin main --allow-unrelated-histories
- git add .
- git commit -m "First commit sentence."
- git branch -m master main
- git push -u origin main
- Refresh the window for your repository on GitHub and see your updates. You should now see your .txt file in your repository.
- This can also be done directly in VSCode
- Create a new folder on your machine where you want to put this repository if you don't already have one you want to use.
- Copy the Clone or Download path for this repository from GitHub.
- In VSCode from the command pallette (Ctrl-Shift-P) run Git: Clone
- Paste the path into the path field which pops up
- Select your new folder you created on your machine
- A new folder for the repository with the repository files should be in the folder you selected showing in the Explorer window in VSCode on the left side.
2022 update: I have created an alternate assignment which does not require the use of the command line. It describes how to work only in GitHub using the web interface or working on your own machine using VSCode after you have git and VSCode installed. It can be found here: https://github.com/cmcntsh/gitHubForClassAssignments
- On this current GitHub repository, scroll to the top and look for a button that says
fork. - Click the
forkbutton. (This copies all the code from the original repository into a new repository on your own GitHub account.)
-
Go to your forked repository on GitHub. It should appear under
Your repositorieswhich is next to theNew repositorybutton. -
Click on the green
clone or downloadbutton and copy the URL. -
Open a terminal window and navigate to the folder where you keep work for this class.
-
Run
git clone [the url you copied]. (That copies the repository from your account on GitHub to your computer so you can make changes.) -
This can also be done directly in VSCode
- Create a new folder on your machine where you want to put this repository if you don't already have one you want to use.
- Copy the Clone or Download path for this repository from GitHub.
- In VSCode from the command pallette (Ctrl-Shift-P) run Git: Clone
- Paste the path into the path field which pops up
- Select your new folder you created on your machine
- A new folder for the repository with the repository files should be in the folder you selected showing in the Explorer window in VSCode on the left side.
- Open the folder in your coding IDE.
- Make a change in a file.
- Run through the steps to push your changes to your remote repository ( status, diff, add, commit, push ).
- Since you've cloned this repository, it is already pointing to your forked version. Therefore, you don't need to tell your computer where to push the code.
3. Creating a pull request (and some extra practice cloning a repository to your computer) (Statistics students can skip this part.)
- Delete the folder on your computer for the forked repository.
- Re-clone the fork to your folder where you keep work for this class.
- Make a change to any file.
- Run through the process of pushing to GitHub ( status, diff, add, commit, push ).
If groups of individuals are working on the same project and everyone pushes code to one repo without verifying the quality of the code, things can get messy pretty quick. GitHub fixed this solution with 'Pull Requests.' Basically, you fork a project, make changes to your fork, then you make a Pull Request (PR) back into the original project requesting that some piece of code be added to the original repo. This is how the vast majority of open source code projects work. In this step, we will make a pull-request.
This part is optional. I'm leaving these instructions here so you are aware about pull requests. But we won't be working with this functionality this semester. Feel free to try it out if you want.
- Go to your forked repo on GitHub.
- Locate the button that says
Pull Requestand click it. - Locate the green button that says
New pull requestand click it.- You should now see the file changes you've made and how they differ from the original repo.
- Click on the
Create pull requestbutton to submit your PR. - Now if you navigate to the original repository and take a look at the
Pull Requestsyour new pull request should be there.