Getting Started with Git & GitHub
Setting Up Git & GitHub on HiperGator
To get started with Git on HiperGator for our collaborative projects, follow these detailed steps:
- Create a GitHub.com account:
- Navigate to GitHub.com and click the Sign up button.
- Enter the requested information to create your account.
- Log in to HiperGator: Open a terminal and login to HiperGator using your gatorlink credentials.
- Generate SSH Keys:
- Generate a new SSH key pair using the following command in the terminal:Replace
ssh-keygen -t ed25519 -C "your_github_email@example.com"
your_github_email@example.com
with your actual GitHub email address. Create a passphrase when prompted (note: this is not compatible with Jupyter Lab). - Retrieve the public portion of your SSH key with:
cat ~/.ssh/id_ed25519.pub
- Copy the SSH key and add it to your GitHub account by following the steps in this tutorial. 4.Test the SSH Connection:
- Ensure that GitHub is recognized by your machine:Follow the prompts to add GitHub to your known hosts.
ssh -T git@github.com
- Generate a new SSH key pair using the following command in the terminal:
- Configure Git:
- Set your username and email in Git with the following commands:Replace
git config --global user.name "John Doe" git config --global user.email "johndoe@example.com"
John Doe
andjohndoe@example.com
with your name and email. - Set the default editor to vim (or your preferred editor):
git config --global core.editor vim
- Ensure you have two-factor authentication and SSH keys set up for GitHub to secure your account.
- Set your username and email in Git with the following commands:
- Setting up Two-factor Authentication:
- As a best practice, it’s highly recommended to enable two-factor authentication whenever possible. GitHub supports this feature and it can be configured under the Security section in your account settings.
Creating a Repository
- To create a new repository, start by navigating to GitHub. Click the
+
icon in the top right corner and selectNew repository
. Name your repository (e.g., planets) and leave the other settings at their defaults before clickingCreate repository
. - If you’ve set up your GitHub account to use SSH keys, make sure to select the SSH option. If you haven’t, stick with the HTTPS option.
- Once your repository is created, it will be empty. To begin adding content, you can follow the steps provided by GitHub under “…or create a new repository on the command line.” Here’s a streamlined approach that you can follow on your local machine or a remote server like HiPerGator:
- Log into your server or open your terminal:
ssh gatorlink@hpg.rc.ufl.edu
- Create a directory named
planets
:mkdir planets
- Navigate into this directory:
cd planets
- Initialize a git repository:
git init
- Create a README file and add initial content:
echo "# planets" >> README.md
- Track changes to the README file:
git add README.md
- Commit the changes:
git commit -m "first commit"
- Set the default branch name to ‘main’:
git branch -M main
- Link your local repository to GitHub:
git remote add origin git@github.com:your_username/planets.git
(replaceyour_username
with your actual GitHub username) - Push the changes to GitHub:
git push -u origin main
- Log into your server or open your terminal:
If SSH keys are not set up, you will be prompted for your GitHub username and password during the push command.
Basic Git Commands
To make changes in your repository, you can use a command line or a text editor. For example, to create a new file named mars.txt
, you might use Nano:
nano mars.txt
Add some text to the file, save, and exit the editor. You can check the contents of your directory with:
ls
This will show the files in your directory, including mars.txt
and any others like README.md
.
To check the status of your repository, use:
git status
This command will show any untracked or changed files. For example, mars.txt
will appear as an untracked file. To track changes to this file, use:
git add mars.txt
git status
This will update the status to show mars.txt
as a staged file ready for committing. You can commit these changes with:
git commit -m "Start notes on Mars as a base"
git status
After committing, if you check the status, you’ll see a message indicating that your branch is ahead of ‘origin/main’ by one commit, suggesting you might want to push your changes to the remote repository on GitHub:
git push
This command transmits your local changes to the GitHub repository. Refreshing your GitHub page will show the new mars.txt
file and the commit message.
Next, we further modify mars.txt
and check the changes:
git status
git diff
git diff
will display the exact changes made since the last commit. To include these new changes in the repository, run:
git add mars.txt
git commit -m "Add concerns about effects of Mars' moons on Wolfman"
git push
This final push will update the remote repository with all recent changes.
Additional Resources and Guides
There are numerous excellent tutorials available for learning both Git and GitHub. Below is a list of resources that I have found particularly useful in developing this training:
Source | Notes |
---|---|
Software Carpentry Version Control with Git | A well-regarded module from the Software Carpentry curriculum, designed for a 3-hour instructor-led session but also suitable for self-study. |
GitHub Learning Lab | Offers a variety of lessons that guide users through hands-on exercises to learn Git and GitHub functionalities directly on the platform. |
Try GitHub | Provides additional GitHub tutorials. |
GitHub Education | Contains information on educational discounts and benefits, which are updated regularly. |
GitHub Classroom | An excellent resource for instructors using Git in the classroom. It facilitates the management of both individual and group assignments and offers classroom tools and freebies like stickers. |
GitHub Pages | Guides on using GitHub to host websites. |
Bitbucket | Another popular Git repository hosting service, offering an alternative to GitHub. |
GitLab | Provides additional options for Git hosting, with comprehensive features for collaboration. |