Git & GitHub Bootcamp

Python Discord

What is Git?

A type of Version Control System

  • Keeps track of changes in your code and who made the changes
  • You take "snapshots" of the code, called commits
  • Your project, and its entire commit history, is called a repository (repo)
  • Your repo can keep track of different versions of your code with branches

Where does Git run?

  • Git runs locally on your computer
  • It keeps track of the history (and your git settings) in a folder called .git
  • You can push code from your computer to a a hosted environment (i.e. GitHub, GitLab)
  • You can fetch or pull code from that hosted environment to your computer

Let's Install Git

Windows

  1. Download from git-scm.com
  2. Launch the installer and select default options

Mac

  1. Install homebrew (if you haven't)
  2. Install git
    brew install git

Linux

Examples:
							
								apt-get install git
								pacman -S git
								yum install git
							
						

Configuring Git

Now that we have git installed, we need to run a few commands to get it set-up.


						git config --global user.name "Your Username Here"
						git config --global user.email "your@email.here"
					

By default, git will use your default test editor for your commits. If you'd like to change it, this is the command to run.

git config --global core.editor path_variable_for_editor_here

In general, something like nano, notepad++, or vim is recommended.

How do we use Git?

  • With a brand new project, the first thing we have to do is tell git we want to track files at all.
    git init
  • Let's see what's in our folder now
    git status

Awesome! Git is now tracking this folder. Let's talk about commits now.

Let's make our first git commit

Committing a file is us telling git that we want to save the current code as a point in history.

  1. We add the files we want to commit to our staging area
    To add all files:
    git add .
    To add specific files:
    git add hello_world.py
  2. Let's write our commit message, telling other people what is changing
    This will open your editor to write a message:
    git commit
    For short and sweet commits you can do:
    git commit -m "Title" -m "Description"

VSCode and PyCharm have git interfaces if you'd rather not use the terminal.

What happens when we git commit?

Committing a file tells git we want to save the current code as a snapshot, a point in history we can revisit if we have to.

What happens when we make a second commit?


                            print("hello world")
                            print("hello Python Discord!")
                        

                            git add .
                            git commit -m "Add another hello print"
                        
00

How does git branch work?

What is branch?

A branch is a different version of your codebase where you can have different commits and a different commit history.

Why do we use branches?

Branches allow you to work on different versions of your code and switch between them easily.

You can merge branches together and git will do the behind-the-scenes work of fitting together the different commits into one cohesive history.

main 00

Branching Strategies

Branches are used to separate production-ready code, often called the main or master branch, from developmental, unstable code.

New branches are often made when implementing an additional feature, or fixing a bug.

Git and GitHub

Git - version control; software responsible for tracking changes to your files
Handles committing, merging, branches, push, and pulling


GitHub - a git forge; online service to store git repositories
Has additional features such as:

  • Forking - allowing others to make their own copy of a repository
  • Pull Requests - merge branches with the opportunity to review and request changes

Hooking up Git and GitHub

SSH Information goes here

Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect GitHub without supplying your username and password each visit.

Setup

  • Create a new SSH key --needs a link--
  • Add your SSH key to GitHub --needs a link--

Further Reading

  • GitHub's SSH guide --needs a link--

Personal Access Tokens goes here

Are SSH tokens just a bit too much for you to deal with? You can use GitHub's Personal Access Tokens.
See this guide: --link goes here--

Working with Git & GitHub

You know how to work with git locally and you have GitHub setup. Let's work with them together.

  • Let's push our local repository to GitHub, that way others can access it
  • git push args here
  • Typing that URL each time is going to get annoying, let's add it as a repo alias
  • git repo add args or whatever here

Someone made changes to the repository, let's pull down those changes so we can view it locally.

  • The person who made the changes needs to push it to GitHub
  • We can pull down the changes to our local machine
  • git pull args here

The little image/graph thing goes here

GitHub's Additional Features

Pull Requests & Reviewing

  • A pull request allows your changes to be merged with the original repository.
  • It must be reviewed and accepted, before it can be merged.
  • In GitLab, these are called merge requests.

Forking

Forking creates your own copy of a repository, of which you are in control.

Pull requests can be opened to apply changes to the original repository.

Actions

GitHub Actions automates the menial tasks, like running tests and publishing packages.

What if I don't like the command line?

  • GitHub Desktop
  • GitKraken
  • VSCode with Git
  • PyCharm with Git

Guidelines, Clarifications, & Further Reading

How to write good commit messages

Let's give a nice and quick rundown of what a good commit is and all the components

Maybe even a "dissection" of an example commit, pointing out all the pieces

What is an atomic commit?

Have Seb write something

Pull vs Fetch

Merge vs Rebase

References & Cheatsheets

Let's practice!