About the Course
What is Github?
Github is a version control system that allows you to track changes to your code. It also enables collaboration among multiple developers on the same codebase.
In simpler terms, think of Github as a place to store your code online (in a repository). By pushing your changes to this online repository, you can:
- Maintain a complete backup and history of all your code changes.
- Invite others to collaborate on your project.
- Deploy your code to the internet via integrated platforms like Vercel, Heroku, and Netlify.
We will be using Github to setup our projects for this course so we can ultimately deploy our apps to the internet.
Github Terminology
The following is a walkthrough of what the online Github application looks like once you already have a repository set up!
Github Online
Repository
A repository (or βrepoβ) is a storage space for your project. You can think of a repository as a fancy word for a folder. It contains all your project files and the history of changes made to them.
- Local Repositories: Repositories on your local computer.
- Remote Repositories: Repositories on Github.
The local version stores you code on your computer where you can make edits and changes. The remote version is the version of your folder that you want to save and share with others.
The above is an image of someoneβs Github account where there are three different remote repositories. Each of these represents a different project.
Commit
A commit represents a snapshot of your project at a specific point in time. When you commit, you save the current state of your project along with a message that describes the changes.
Once you push your commits to your remote repository, you will be able to see the commits! You can see the code diff per commit as well.
Gitignore file
The gitignore file is a text file that tells Git which files to ignore in your project (in other words, which files should not be uploaded (or committed) to the remote repository). This is useful for ignoring files that are large, binary, or otherwise not intended to be shared like .env files.
To save time, you can ask Cursor to create a gitignore file for you. Make sure to ask it to include the .env file. This is an example of a gitignore file:
# build outputdist/.output/
# dependenciesnode_modules/
# logsnpm-debug.log*yarn-debug.log*yarn-error.log*pnpm-debug.log*
# environment variables.env.env.*!.env.example
# macOS-specific files.DS_Store
# Editor directories and files.vscode/.idea/*.suo*.ntvs**.njsproj*.sln*.sw?.vercel/*
The Primary Github Workflow
- Create a new repository on Github and clone the repository to your local machine OR clone an existing repository to your local machine.
- Make changes to the code locally.
- Commit the changes to the local repository.
- Push the changes to the remote repository on Github.
Github Workflow
Workflow How-Tos:
Initializing a Repository (Creating a New Project)
There are two common methods:
- Directly from Your Local Machine:
In your project directory, run:Terminal window # Initialize a new Git repositorygit init# Stage all files for commitgit add .# Commit with a descriptive messagegit commit -m "Initial commit"# Add the remote repository (replace URL with your repository's URL)git remote add origin https://github.com/yourusername/your-repo.git# Push your changes to the main branch on Githubgit push -u origin main - Using the Github Website:
- Create a new repository on Github.
- Clone it to your local machine.
Cloning a Repository
Cloning downloads a Github repository to your local machine:
git clone https://github.com/username/repository.git
After cloning, you have a complete copy of the repository locally.
Adding, Committing, and Pushing Change
The most common Github workflow is basically where you make changes to your code locally on your computer, and then push those changes to the remote repository on Github when youβre ready to save your changes (seem above image).
To update your repository with new changes:
git add .git commit -m "Describe your changes here"git push -u origin main
This process ensures your changes are saved locally and synchronized with your remote repository.
Stashing Changes
Stashing is a helpful way to save work-in-progress without committing the changes. The following commands are all the commands related to shashing
git stash # stash your changesgit stash list # list your stashesgit stash pop # apply your stashed changes
Checking the status of your repository
git status # check the status of your repositorygit log # check the commit historygit diff # check the changes you made to a filegit branch # list all the branches in your repository
Reverting Changes
If you need to undo changes, consider the following commands:
git revert <commit-hash> # revert the changes made in the commit with the given hashgit reset --hard # reset your changes to the previous commit, use this command with caution
Git Practice!
- Create an empty NextJS project.
- Run this project locally (to see what it looks like).
- Create a .env file with a dummy key.
- Initialize your git repository.
- Add a git ignore file (include the .env file and the node_modules folder).
- Add all the git files to your repository.
- Push the changes.
- Look on your online Git account to make sure that all the folders in your project are there (and the .env file and node_modules folders are NOT there).
- Now, make a slight modification to the text in the main landing page (you can ask Cursor to help you with this).
- Add, commit, and push your changes. Voila, you have created a new repository, and pushed incremental changes to it!
TODO: Add in video showing me going through the steps of doing this.
More Advanced Github Features
We have only scrated the surface of what commands are available in Github. We have mainly focused on the commands where you are working on the repository alone. When you start collaborating with others, you will wnat to learn the concept of branching and pull requests.
Pulling Changes
Branches
Pull Requests
Merging
Forking
We would recommend looking into the resources below to learn more about these concepts.
Resources
For more detailed guidance on using Github, check out these resources: