Git & GitHub
a lesson on version control
What is version control?
- Version control is software used to manage changes and updates to code, programs, and documents
-
Usually used for collaborative programming
- A team works on a single project together and uploads their code as different versions or "branches" of the main code
- Also used for solo work to manage the versions of your software
What is Git?
- Git is a popular form of version control
- Used to upload, download, and configure source code to/from sites
- Used through the CLI
- Each project is a repository (repo) that is localized as a directory
What is GitHub?
- GitHub is a popular website used to host projects and source code through Git
- You may have heard of it or even used it before
- You can fully work on your projects and manage it through the site, but we will teach you how to do everything with Git
Tour of GitHub
Some Git commands
- git clone <url of repo> to download the repo locally for the first time
- git init to create an empty Git repo
- git add <files> to add files to the index to be committed
- git commit -m "message" to record your changes to the repository with the given message
- git push to update the repository on the internet
- git pull to get the changes that are on the internet from the repo or another branch
-
git checkout <branch> to switch branches
- Use with the -b option to create a new branch
- git merge <branch> to merge/combine the given branch/version with the current branch
- git status to show the status of the working tree
More Commands
- The commands in the previous slide are the ones you'll mostly be using
- There are a lot more, but make sure you pay attention to any messages/errors you get that will tell you to use another one and think critically!
- Check the manual (man git) to see a list of the Git commands
- If you'd like to see the manual for a specific command (i.e. git add), it's written as a single hyphenated word, not two spaced out words
- man git-command, where "command" is the command you want to read about (i.e. man git-add)
- If you'd like to see the manual for a specific command (i.e. git add), it's written as a single hyphenated word, not two spaced out words
Basic steps to update a repo
- git pull (if there are any changes to be pulled)
- Edit the files and do your work
- (Optional) git status
- git add <files> (or just . for the entire directory instead of typing out the individual files)
- git commit -m "commit message"
- git push
Use git clone <URL> to download the repo locally for the first time
git status between the steps (especially before adding) if you want to make sure everything is doing what you want it to do!
What now?
- Try Git
- Create an account on GitHub
- Clone or initialize a new repository for your current project
- Move your project files to that repo directory
- After working on your project, do the steps on the previous slide to push your changes
- Always push your projects to GitHub at the end of the day so we can see your progress too!
Do NOT edit your files directly from GitHub or do anything with the website. We expect to only see you use the CLI
Git & GitHub
By jtheadland
Git & GitHub
- 772