Git tips and tricks
Basic Git & GitHub Guide for Scientific Projects
About
This guide is for beginners who are new to Git and GitHub. It walks you through the process of setting up Git on your computer, creating a GitHub account, learning basic commands, and joining a GitHub organization (e.g., rlaplaza-lab). In the near future, it will probably be helpful to do the same in the supercomputers you use as well.
Step 1: Create a GitHub Account
- Go to https://github.com
- Click Sign up
- Choose a username, enter your email, and create a secure password
- Verify your email and follow the on-screen instructions
Step 2: Install Git
On macOS
Use Homebrew:
brew install git
On Ubuntu/Debian
sudo apt update
sudo apt install git
On Windows
Download from the official site: https://git-scm.com/download/win
Follow the installer with default settings.
Step 3: Set Up Git
Open your terminal or Git Bash and configure Git with your name and email:
git config --global user.name "Your Full Name"
git config --global user.email "your@email.com"
You can check the configuration with:
git config --list
Step 4: Generate an SSH Key (Optional but Recommended)
This allows you to securely connect to GitHub.
ssh-keygen -t ed25519 -C "your@email.com"
Then add your key to the SSH agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Copy your SSH public key:
cat ~/.ssh/id_ed25519.pub
Go to GitHub SSH settings, click “New SSH key”, and paste the key there.
Step 5: Request Access to rlaplaza-lab
- Contact Ruben and share your GitHub username
- You will be invited to the rlaplaza-lab GitHub organization
- Accept the invitation via email or at https://github.com/orgs/rlaplaza-lab
Step 6: Clone a Repository
Once you have access to a repository, you can clone it to your computer:
git clone git@github.com:rlaplaza-lab/project-name.git
Or with HTTPS:
git clone https://github.com/rlaplaza-lab/project-name.git
Step 7: Basic Git Commands
Check project status
git status
Add changes to staging
Staging is a temporary area that holds the changes you plan to make to the repository. Adding changes to staging is how you tell Git which of your edits should go into the next commit.
git add filename.py
Or add everything:
git add .
Commit changes with a message
A commit is a snapshot of the repository. Once all the changes you want are staged, you save them together in a single commit.
git commit -m "Describe your changes clearly"
Push changes to GitHub
Now we can upload our commit to the remote repository on GitHub.
git push
Pull latest changes from GitHub
We can also download the latest commits from the remote repository. It is possible to push and pull from different branches, but we do not cover that here.
git pull
Step 8: Best Practices
- Commit often with clear messages
- Use branches for new features or experiments:
git checkout -b new-feature - Keep your
mainormasterbranch clean - Pull often to avoid conflicts
- Document your code and changes in a
README.mdorCHANGELOG.md
Resources
- Introduction to Github by the excellent Prof. Ayers
- Git Book (free)
- GitHub Docs
- Git Cheat Sheet
- Oh My Git! Game – Learn Git by playing
- GitHub Student Developer Pack – Free tools for students