Please sign up for a GitHub account.
To follow along on Windows, please install Windows Subsystem for Linux (WSL)
by running the following command in PowerShell or Windows Command Prompt in administrator mode:
wsl --install
To follow along on macOS, please install git. (Note: To enter commands in a terminal: open Finder, go to Applications, enter the Utilities folder, and open Terminal.)
To follow along on Linux, please follow these instructions to install git: https://github.com/git-guides/install-git#install-git-on-linux
- macOS: Finder → Applications → Utilities → Terminal
- Windows: Use the start menu item for Windows Subsystem for Linux or WSL
- Linux: ctrl + alt + T
We can assign ourselves as the author of changes with the following command — making sure to change "Your Name" to your name!
git config --global user.name "Your Name"
We can optionally provide an email address that will show up in the
git
history.
git config --global user.email "[email protected]"
GitHub made its authentication process more strict in 2023, so now we have to take some extra steps for security. It's rather annoying, but typically need to be done once per computer.
Please follow the instructions (which depend on the operating system) at:
Note
Use the links above to set up an SSH key on macOS or Windows, unless using WSL.
-
Run the following command, changing your email address to the one associated with your GitHub account.
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519 -N ""
-
Next run:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
-
Copy the contents of the file
~/.ssh/id_ed25519.pub
.
In a Unix terminal, the commandcat
(short for "concatenate") prints out the contents of a file.cat ~/.ssh/id_ed25519.pub
-
Go to https://github.com/settings/profile
- In the "Access" section of the sidebar, click on "SSH and GPG keys"
- Enter a descriptive title like "home laptop"
- Click New SSH key or Add SSH key
- In the Key field, paste what was copied in the previous step.
- Click Add SSH key.
We can fork a repository to make our own copy of it on GitHub.
- Log in to GitHub.
- Go to: https://github.com/PlasmaPy/git-demo
- Towards the upper right, click on the Fork button.
- In the lower right, click on Create Fork.
- Go to your fork of the repository
- Click on the green button that says "<> Code ▼"
- Select the SSH tab
- Click on the copy button "⧉"
- In a terminal, type
git clone
followed by a space and then paste the text that you copied. The command should be like:git clone [email protected]:your-github-username/git-demo.git
- Type
cd git-demo
to enter the directory containing the clone, and typels
to see the contents.
A remote is the address of a repository hosted on GitHub. The most common convention is to define:
upstream
as the primary repositoryorigin
as our fork of the repository
-
Define the primary repository as the
upstream
remotegit remote add upstream [email protected]:PlasmaPy/git-demo.git
-
To verify that the remotes have been entered correctly, type:
git remote -v
This should display four lines, with
origin
pointing to your fork andupstream
pointing to the primary repository.
-
Update our clone so that it knows the current state of the primary and forked repositories:
git fetch --all
-
Next, create a branch to make our changes in, and immediately switch to it. We can change
feature-branch
to a more descriptive name.git checkout -b feature-branch upstream/main
A branch is a separate/isolated version of a project. Using branches lets us make an independent and isolated set of changes. These changes later merge back into the
main
branch. -
We created a branch on our computer. Next we need to link that branch to GitHub.
git push --set-upstream origin feature-branch
-
Edit a file and save the changes. In a Unix shell, we can add text to a new file using
echo
(which prints out a string) and>
(which redirects the output of a command into a fil).echo "Hello, I'm Nick!" > new_file.txt
-
To line up the changes that we want to record as a snapshot in history, run:
git add new_file.txt
This step is like putting items in a box that we want to mail.
-
To commit the changes (and preserve a snapshot of what each file looks like at this time in history), run:
git commit -m "Add new file"
The
-m
is short for--message
. We use the commit message — the text in quotes — to describe the changes that we made. This step is like closing the box and putting it in outgoing mail. -
After one or more commits, send (push) the changes to GitHub.
git push
This step is like mailing a box to GitHub.
We're almost there!
- Go to https://github.com/PlasmaPy/git-demo.git
- There will usually be a banner that says something like "Make pull request". Click on it.
- Add a title like "Add blank file" and (optionally) a description.
- Click on submit pull request.
- Congratulations!
Note
The banner might not appear if there was already a pull request, then:
- Click on the "Pull requests" tab towards the upper left
- Click on "New pull request" toward the upper right
- Click on the link that says "compare across forks"
- Make sure that base respository is
PlasmaPy/git-demo
, base ismain
, and head repository isyour-github-username/git-demo
. - Click on
compare: main
, and selectfeature-branch
under branches. - Click on "Create pull request"