Lesson 3 — Pushing to GitHub
Learning Objectives
Section titled “Learning Objectives”- Create a new repository on GitHub through the web interface.
- Connect a local repository to a GitHub remote with
git remote add. - Upload commits to GitHub with
git push. - Download updates from GitHub with
git pull. - Clone an existing GitHub repository with
git clone. - Understand the difference between
origin,main, andHEAD.
Conceptual Overview
Section titled “Conceptual Overview”What is a remote?
Section titled “What is a remote?”A remote is a version of your repository that lives somewhere else — in this case, on GitHub’s servers. You can have several remotes, but the most common one is called origin by convention. When you push, you are sending your local commits to the remote. When you pull, you are fetching commits from the remote and merging them into your local branch.
The push/pull cycle
Section titled “The push/pull cycle”Local machine GitHub (origin)───────────── ───────────────edit filesgit addgit commit ──── git push ──► repository ◄─── git pull ─── (updated by a collaborator)HTTPS vs SSH
Section titled “HTTPS vs SSH”GitHub supports two ways to authenticate when pushing:
- HTTPS — you use your GitHub username and a Personal Access Token (PAT) as the password.
- SSH — you use the SSH key you set up in Lesson 1. No password needed after setup.
This module uses SSH throughout because it is more convenient once configured.
Worked Examples
Section titled “Worked Examples”1) Create a repository on GitHub
Section titled “1) Create a repository on GitHub”- Go to
https://github.com/newin your browser. - Fill in the fields:
- Repository name:
my_analysis(match the folder name from Lesson 2) - Description:
Bioinformatics analysis scripts and notes - Visibility: Public (or Private — both work the same way)
- Do NOT tick “Add a README file”, “Add .gitignore”, or “Choose a license” — you already have these locally.
- Repository name:
- Click Create repository.
GitHub will show a page titled “Quick setup”. Leave this page open — you will need the SSH URL in the next step.
2) Copy the SSH remote URL
Section titled “2) Copy the SSH remote URL”On the “Quick setup” page, make sure SSH is selected (not HTTPS). The URL looks like:
git@github.com:YourUsername/my_analysis.gitCopy this URL.
3) Add the remote to your local repository
Section titled “3) Add the remote to your local repository”Go back to your terminal and navigate to your project:
cd ~/projects/my_analysisAdd the remote. origin is the name you give to this remote — it is a universal convention:
git remote add origin git@github.com:YourUsername/my_analysis.gitNo output is expected when this command succeeds.
Verify it was added:
git remote -vOutput:
origin git@github.com:YourUsername/my_analysis.git (fetch)origin git@github.com:YourUsername/my_analysis.git (push)Two lines appear: one for fetching (downloading) and one for pushing (uploading). Both point to the same URL.
4) Push your commits to GitHub
Section titled “4) Push your commits to GitHub”git push -u origin main uploads your local main branch to the remote named origin. The -u flag links the local branch to the remote branch — after this first push you only need to type git push in future.
git push -u origin mainOutput:
Enumerating objects: 14, done.Counting objects: 100% (14/14), done.Delta compression using up to 8 threadsCompressing objects: 100% (10/10), done.Writing objects: 100% (14/14), 1.23 KiB | 1.23 MiB/s, done.Total 14 (delta 2), reused 0 (delta 0), pack-reused 0remote: Resolving deltas: 100% (2/2), done.To git@github.com:YourUsername/my_analysis.git * [new branch] main -> mainbranch 'main' set up to track 'origin/main'.Go to https://github.com/YourUsername/my_analysis in your browser. Your files are now online.
5) Make a change locally and push it
Section titled “5) Make a change locally and push it”Edit notes.md:
nano notes.mdAdd a new line at the bottom:
- Pushed repository to GitHub successfullySave and exit. Stage, commit, and push:
git add notes.mdgit commit -m "Note successful GitHub push"git pushOutput:
Enumerating objects: 5, done.Counting objects: 100% (5/5), done.Delta compression using up to 8 threadsCompressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 320 bytes | 320.00 KiB/s, done.Total 3 (delta 1), reused 0 (delta 0), pack-reused 0To git@github.com:YourUsername/my_analysis.git f4a52b1..8e12ab3 main -> mainRefresh the GitHub page for your repository. The commit message appears in the file list.
6) View commits on GitHub
Section titled “6) View commits on GitHub”On your repository page, click the clock icon that shows the number of commits (e.g. “7 commits”) near the top right of the file list. GitHub shows the full commit history with messages, authors, and timestamps — the same information as git log.
7) Edit a file directly on GitHub
Section titled “7) Edit a file directly on GitHub”GitHub allows you to edit files in the browser. This is useful for small changes like fixing a typo in a README.
- Go to your repository page on GitHub.
- Click on
README.md. - Click the pencil icon (Edit this file) in the top right.
- Add a line at the bottom:
Maintained by: Your Name - Scroll down to the “Commit changes” section.
- Enter the message:
Add maintainer name to README - Click Commit changes.
The change now exists on GitHub but not yet on your local machine.
8) Pull the change to your local machine
Section titled “8) Pull the change to your local machine”git pull fetches the latest commits from the remote and merges them into your current branch.
git pullOutput:
remote: Enumerating objects: 5, done.remote: Counting objects: 100% (5/5), done.remote: Compressing objects: 100% (3/3), done.Unpacking objects: 100% (3/3), done.From github.com:YourUsername/my_analysis 8e12ab3..9f23bc4 main -> origin/mainUpdating 8e12ab3..9f23bc4Fast-forward README.md | 1 + 1 file changed, 1 insertion(+)Confirm the change is now in your local file:
tail -n 3 README.mdOutput:
Samples: SRR1553607, SRR1553608, SRR1553609Maintained by: Your Name9) Clone an existing repository
Section titled “9) Clone an existing repository”git clone downloads a complete copy of a remote repository (all files and full history) to your local machine. This is how you start working on a repository that already exists on GitHub — for example, a collaborator’s project or a public tool.
Clone the Bioinformatic Fridays repository as an example (read-only, no login needed):
cd ~git clone git@github.com:wave-cu/Bioinformatic_Fridays.gitOutput:
Cloning into 'Bioinformatic_Fridays'...remote: Enumerating objects: 45, done.remote: Counting objects: 100% (45/45), done.remote: Compressing objects: 100% (38/38), done.Receiving objects: 100% (45/45), 25.14 KiB | 1.40 MiB/s, done.Explore the cloned repository:
ls Bioinformatic_FridaysOutput:
Module_1_Linux Module_2_Conda Module_3_Omics Module_4_Recap_Exercises Module_5_Project Module_6_Problem_Solving Module_7_Bash_Scripting README.mdThe entire repository, including all history, is now on your machine.
10) Understand git status after a push
Section titled “10) Understand git status after a push”After pushing, your working directory and remote are in sync. Run:
cd ~/projects/my_analysisgit statusOutput:
On branch mainYour branch is up to date with 'origin/main'.
nothing to commit, working tree clean“Your branch is up to date with ‘origin/main’” means your local branch matches what is on GitHub exactly.
Exercises
Section titled “Exercises”-
Go to
https://github.com/YourUsername/my_analysis. Can you see all the files from Lesson 2? Click onrun_fastqc.shand read its contents. -
Create a new file called
methods.mdlocally with a short description of your analysis approach. Stage, commit, and push it. Refresh GitHub to confirm it appears. -
Use the GitHub web editor to add a line to
sample_list.txt(addSRR1553610). Then rungit pulllocally and confirm the new line is present. -
Run
git log --onelineafter pulling. How does the history compare to what you see on the GitHub commits page? -
Challenge: Clone any public GitHub repository you are curious about. Run
git log --onelineinside it. How many commits does it have?
Solutions
Section titled “Solutions”Solution 1
Section titled “Solution 1”Go to https://github.com/YourUsername/my_analysis. Files listed: README.md, notes.md, sample_list.txt, run_fastqc.sh, environment.md, .gitignore.
Solution 2
Section titled “Solution 2”cd ~/projects/my_analysisnano methods.mdFile content:
## Methods
1. Quality control with FastQC2. Adapter trimming with Trimmomatic3. Alignment to reference genome with BWA-MEM4. Variant calling with GATK HaplotypeCallergit add methods.mdgit commit -m "Add analysis methods overview"git pushSolution 3
Section titled “Solution 3”On GitHub: navigate to sample_list.txt, click the pencil icon, add SRR1553610 on a new line, commit the change.
Back in the terminal:
git pullcat sample_list.txtOutput:
SRR1553607SRR1553608SRR1553609SRR1553610Solution 4
Section titled “Solution 4”git log --onelineThe list should match the commits shown on the GitHub commits page exactly, in the same order.
Solution 5
Section titled “Solution 5”git clone git@github.com:wave-cu/Bioinformatic_Fridays.git ~/bfridays_clonecd ~/bfridays_clonegit log --oneline | wc -lThe number printed is the total commit count.