Git and GitHub Workshop
Git and GitHub Workshop
Audience: First-year Masterβs students (new to coding and version control)
Objective: By the end of these instructions, you will be able to:
β
Create a GitHub repository
β
Clone it to your computer
β
Make changes, commit them, and push updates to GitHub
π Why Use Git and GitHub?
Git is a tool that helps you track changes in your code over time. GitHub is a platform that stores your code online and allows you to share it with others.
With Git and GitHub, you can:
- Keep a history of your changes
- Work on projects from different computers
- Collaborate with others easily
π οΈ Setup Requirements
β Install Git on your computer:
- MacOS: Open Terminal and install Git using Homebrew:
brew install git
Windows: Download and install Git from https://git-scm.com.
Linux: Install Git using your package manager:
sudo apt install git
β Create a GitHub account:
- Go to https://github.com and sign up.
1. Create a Repository on GitHub
- Open https://github.com and log in.
- In the top-right corner, click the + icon β New Repository.
- Fill out the repository details:
- Repository name:
my-first-repo
- Description: (Optional)
- Set it to Public (or Private if preferred)
- Check Add a README file
- Repository name:
- Click Create repository
β Youβve created your first repository!
2. Clone the Repository to Your Computer
- Open your repository on GitHub.
- Click the green Code button β Select SSH β Copy the SSH URL.
- Open a terminal (Command Prompt, Git Bash, or similar).
- Navigate to a directory where you want to store your project:
cd ~/Documents
- Clone the repository:
git clone git@github.com:your-username/my-first-repo.git
- Change into the repository folder:
cd my-first-repo
β Youβve now downloaded a local copy of your repository.
3. Make Changes to a File
- Open the repository folder in a text editor (like VS Code).
- Open the
README.md
file.
- Add a line of text:
This is my first repository for my coding project.
- Save the file.
β Youβve made your first change!
4. Stage, Commit, and Push Changes
Now you need to tell Git to track and save these changes.
π Step 1: Check the Status
In the terminal, check which files have changed:
git status
You should see the README.md
file listed as modified.
π Step 2: Stage the Changes
Stage the file so Git knows to track it:
git add README.md
π Step 3: Commit the Changes
Create a snapshot of the changes and add a descriptive message:
git commit -m "Added personal message to README"
π Step 4: Push the Changes
Send the changes to GitHub:
git push
β Check your repository on GitHub β Refresh the page β Your new content should be visible!
5. Make More Changes (Optional)
- Open the
README.md
file again.
- Add another line of text:
Hereβs a second change to my repository.
- Save the file.
π Repeat the Git Workflow
- Check status:
git status
- Stage the change:
git add README.md
- Commit the change:
git commit -m "Added second line to README"
- Push the change to GitHub:
git push
β Refresh your GitHub repository to confirm the update.
6. How to Check the History
To see a history of your commits, type:
git log
- Press
q
to exit the log view.
7. Troubleshooting Tips
π‘ Permission denied when cloning?
- Make sure your SSH key is set up correctly. Follow GitHubβs guide on setting up SSH keys here.
π‘ Git asks for your username and password?
- You might not be using SSH. Double-check that you copied the SSH URL, not the HTTPS one.
π‘ Changes arenβt showing on GitHub?
- Make sure youβve pushed your changes:
git push
β Workflow Summary
- Make changes β Edit your files.
- Stage changes β
git add <filename>
- Commit changes β
git commit -m "Message"
- Push changes β
git push
π― What Success Looks Like
β
A GitHub repository created.
β
Files cloned to your local machine.
β
Successfully edited, committed, and pushed changes to GitHub.
π Next Steps
- Try adding more files and making more commits.
- Explore creating a branch and making a pull request.
- Experiment with resolving conflicts and merging branches.
π Well Done!
Youβve completed the Git and GitHub workshop. Version control will now make your coding projects more organized and stress-free!