Day 23 - Advanced git

Spring 2023

Smith College

Overview

Timeline

  • git Recap
  • git in the Terminal
  • Advanced git
  • Advanced Github

Goal

Learn how to use git to effectively collaborate

git Recap

git as Timelines

The Turing Way

git Workflow

Key Terms

repo
Repository - the collection of git files that contain your project
commit
To save a checkpoint of your project for future reference
revert
Undo all changes made to a file since the last commit
staged
A file that is preparing to be commited, but has not yet been
push
To ‘push’ files from your local machine onto an internet service
pull
To ‘pull’ files from a remote service onto your machine
merge
To combine two branches/files of the same project
conflict
When two files or set of files have changes that cannot be easily merged
checkout
Load in a previous checkpoint (commit) or switch to a branch

git in the Terminal

git commands (but with words)

  1. git add: Stage the file
  2. git commit -m "<YOUR MESSAGE>": Commit staged files
  3. git pull: Pull from GitHub
  4. git push: Push files to GitHub

New git Commands

git status
Check the staging area and what branch you are on.


git log (pro-tip: git log --oneline --graph --decorate --all)
Look at the history of past commits


git diff
Print the differences between the files as it is now and the most recent commit


git revert <FILES>
Undo all changes made to a file since the last commit

Advanced git

git Ignore

The hidden .gitignore file lets you tell git “I do not want you to pay attention to these files or folders.”


This can be very handy if you want to:

  • Ignore all .csv files
  • Ignore your scrap folder
  • Ignore the file containing your API keys
  • etc

Branches

The Turing Way

branch ->

<- merge

git checkout <NAME OF BRANCH>
Switch between branches
git checkout -B <NAME OF BRANCH>
Create new branch and switch to it
git merge <NAME OF BRANCH>
Merge two branches

Advanced Github

Pull Requests

When you push a branch to GitHub, it will ask if you want to make a pull request to merge that branch into main.


Creating a request is the best way to merge your branches, as it allows you to use several powerful collaboration tools.

Pull Request Tools

Dealing with Conflict

Sometimes git/GitHub will tell you there is a conflict.


That’s not uncommon. It means two people worked on the same file and edited the same part of the code.


You need to tell git how to resolve the conflict by opening the file in question and committing the “real” version.

Turn this:

<<<<<<< HEAD

# read in data
read.csv("./data/my_csv.csv")

=======

# read in data using tidy nonsense
read_csv("./data/my_csv.csv")

>>>>>>> ee175895783b64e0e1f696d9456

Into this:

# final code
# read in data
read.csv("./data/my_csv.csv")

And commit then push.

Code Review

Code-Along

What is a Good Branch?

Getting a feel for how large the work done in a branch should be takes some practice. While I can’t give you a single answer, here are some guides to help.

Good Branches

  • Are topically coherent
  • Accomplish a single goal
  • Add a single feature to the project
  • Are closed once pulled into main

Bad Branches

  • Branches for each person on the team
  • Branches per day/week/time period
  • Combines multiple issues/tasks
  • Keeps getting re-used for new tasks

For Next Time

Topic

Package Documentation

To-Do