Welcome to Github Workshop!!
Setup
Make sure you follow these steps thoroughly:
- Git
- Download Git here
- Install Git on your machine
- Open your terminal
-
Run the following code:
git --version
- If you see the git version printed on your terminal good job!!!
- Github
- Do you have a Github account?
- If yes, then ignore the instructions below and move to the text editor step
- If you do not have a Github account head to this site and make one
- Open up a text editor (Notepad, VS-Code, Sublime, nano, vim, etc.)
Git
If you are ever confused about jargon, please visit the
dictionary.
What is Git?
- Git is a version control system used to track changes in files.
- It is commonly used by developers and computer science students to manage code.
- It allows you to view past versions and revert changes—similar to "time travel" for your files.
Commits
- A commit means saving the current state of your project at a specific point in time.
- Think of it like creating a restore point.
- Commits can be made frequently (e.g., daily, multiple times a day, or at milestones).
Example of a Commit
- You are making major changes to a project.
- April 5: You complete most changes and create a commit labeled "90% done".
- April 6: Your manager introduces a bug, and you cannot identify it.
- Because you made a commit, you can revert the project back to the earlier working version.
- Without that commit, fixing the issue could take a long time.
Branches
- A branch creates a separate version of your project from the latest commit.
- Branches are used to test new features safely.
- Once changes are complete, they can be merged back into the main project.
Collaboration
- Imagine two people working in shifts on the same machine
- Each person can make their own branches label them, and communicate how their progress is going in a clean manner
- Everyday the other person can look at the other person's updates, choose to merge or make their own changes
- Near-perfect collaboration without any of the hassles.
Main Concepts
- Commits: A timestamp with all the changes made up to that point saved.
- Branches: A divergence from the main code to work on small bugs/changes`.
- Main/Master Branch: The default branch of a project.
- Merge: Combining changes from one branch into another.
- Collaboration: Git can allow for easier collaboration if instead of a computer you have a server.
Github
- Github is a platform, and not necessarily a software. Think of a huge computer you rent that runs git for you.
- It allows you to store your changes, commits and anything you would store on local
- A Github "repository" can also be made available to multiple people
- Anytime you want to think of github think of two different Git's running simultaneously
- One version where all the coding happens (local machine) one where all these will eventually be stored
- This is where we will be introducing new concepts:
- Push : To push any commits you made on local and update them online
- Pull/Fetch : To "pull" any commits made online (by your team) and download them (if fetching) and integrate them (if pulling)
Dictionary
Quite often I might use jargon to explain certain concepts. Here's a list of all important words and commands to keep a note of
- Track - A verb used to denote that a file is being watched by git
- Stage - An imaginary stage where files that were changed can be put if you would like to save them
- Add - To add new or pre-existing files to the stage
- Commit - To "save" your changes within git
- Commit - To "save" your changes within git
- Push - To "push" your changes within git on local to github
- Pull - To "pull" your changes from github and to download and integrate them
- Fetch - To "fetch" your changes from github and to download them
- Local - Your own machine that is connected to the internet
More Useful Git Commands
Here are some additional basic commands that will help you understand what is happening in your project:
- Status
- Shows the current state of your repository (very useful when confused)
-
git status
- Log
- Displays a history of all commits
-
git log
- Branch (View Branches)
- Shows all existing branches in your project
-
git branch
- Create a New Branch
- Creates a new branch to work on features safely
-
git branch branch-name
- Switch Branches
- Moves you from one branch to another
-
git checkout branch-name
- Create and Switch Branch (Shortcut)
- Merge Branch
- Merges changes from another branch into your current branch
-
git merge branch-name
- Pull Latest Changes
- Downloads and integrates changes from GitHub
-
git pull
- Fetch Changes
- Downloads changes from GitHub but does not merge them
-
git fetch
- Remove a File from Staging
- Unstages a file if you added it by mistake
-
git reset file-name
- Rename a Branch
- Renames the current branch
-
git branch -m new-name
Demo Files
-
git init SASEisawesome
-
cd SASEisawesome
- Open a text editor here and make a file called shapes.html
- Copy over the code from here
- Copy the following lines whenever needed
-
git add -A
-
git commit -m "message"
- Making a key to your github account
- Head to github.com
- Click on your profile picture and then the settings button
- Scroll down till you see developer settings
- On the left pane you will see a dropdown marked "Personal Access Tokens"
- Click on the dropdown and click the Tokens(classic) button
- Click the "Generate new Token" --> "Generate new token (classic)"
- Write down a note
- Check on expiry in one week (to ensure security)
- Click on the repo button and unsure everything below it is also checked
- Create your token and save it safely
- Once you are done with your changes create a repository on github with the same name as the repo you made earlier
- Copy the link given on github, and use the following code to update it