This is a little guide to help you get introduced to git.
Anything that looks like this should be executed in the terminal.
- Install git: https://git-scm.com/download
- Set user info (needed before you can commit)
git config --global user.email "you@example.com"git config --global user.name "Your Name"
- Create github account with your Brock email: https://github.com/
- Get your github education pack: https://education.github.com/pack
- Create a folder called "git-stuff".
- Create a text file in that folder.
- Open either git bash or cmd, and navigate to your folder
git initgit add file.txtgit commit -m "Created file"(Creates a commit with the given commit message)- Open file.txt and type "Hello World". Save, close.
git diff(Shows the difference between your working directory and the git repo)git add .(Adds files in the current directory recursively)git status(Shows the changes that will happen when you commit)git commit -m "Added text"
- Go to github and create a new project: https://github.com/new
- Name it something descriptive, and make it private (So you can control who sees it), then click "Create repository"
- The page you go to gives you instructions on how to push an existing repository (the one you created earlier)
git remote add origin https://github.com/Jesse-longname/something-descriptive.gitgit push -u origin master(When you push, it will ask you to sign in)- Refresh the github page with the instructions. Your repo should be there!
- Locally, add a new file and put some text in it.
- Add it to your repo, and commit it.
git push(Pushes the repo to github)- Refresh your github repo page, and you'll see the new file on it
- On your repo in github, click "Create new file". Name it something, give it some contents, and create it.
- Now we will get it onto your computer
git pull- Go to your folder, and you will see that the new file is there
-
Click the "Fork" icon in the top right to fork this repo to your github account.
-
Navigate to your github page (
https://github.com/<your_user_name>/git-workshop) Click "Clone or download" and copy the url -
Go to your terminal and navigate to a folder that you want the git-workshop folder in. (Cloning creates the folder for you wherever you working directory currently is). Type
git clone [url]in your terminal. -
Now you have the repo locally.
-
Set the upstream repository as per this with
git remote add upstream https://github.com/BrockCSC/git-workshop.git -
Create a branch with your name
git branch Jesse
-
Navigate to the branch
git checkout Jesse
-
Edit the "Fixme.java" file. There are lots of erros in it. Find one or two to fix (spelling mistakes count!), add your changes and commit them.
-
Add and commit them.
-
Check the differences between your branch and the master branch
git diff master(master is the base branch)
-
Checkout the master branch again
-
Now the file you made is gone from your folder! Don't worry, it is still on your branch.
git diff Jesse
-
Once done, switch to your branch and
git push. -
Git will tell you there is no branch called that, so do the command it tells you to do
git push origin Jesse
-
Now go to
https://github.com/<your_user_name>/git-workshopand you'll see your branch and changes under "branches" -
Click on the "Pull request" button in the menu bar just above the repo.
-
Create a pull request to BrockCSC's master branch. You can see the changes between your commit and master. You should only see the changes that you made to the "Fixme.java" file. Create a message for your pull request and submit the PR.
-
Someone from the CSC will review your code and merge your request.
-
Congratulations, you have made your first open-source contribution! Now you can check out any of the literally thousands of open-source repos and do the same! (I recommend