Fixing
A presentation by Tlaloc Barajas and Jonathan Chancey
Image Source: https://xkcd.com/1597/
Topic List
Image Source: https://xkcd.com/1597/
But First!
What is Git?
What is Git?
Why is Git Useful?
Git is good
Why is Git Useful?
Why Should You Learn Git?
Prerequisites
GitHub Account
Know your GitHub credentials.
If you’re new to GitHub, create an account with your school email.�
Git on Windows
There’s 2 main options for getting git on windows
Git on Windows - WSL
Ubuntu on Windows (WSL)�https://docs.microsoft.com/en-us/windows/wsl/install-win10
Git on Windows - MinGW Instructions
Git on MINGW �https://git-scm.com/downloads
Git on Mac - Instructions
If you already have XCode Command Line Tools you may have git.
Try running:� $ git --version
you want an output that looks like this:�
Otherwise just download Git�https://git-scm.com/download/mac
Git on Linux - Instructions
Check your version with:� $ git --version
Otherwise, install Git using your package manager�For example on Ubuntu:� $ apt update� $ apt install git
Environment Setup
Configure your git username and email— this step is required to make commits� $ git config --global user.name "Your firstname and lastname"� $ git config --global user.email "yourschoolemail@ucmerced.edu"
Commands We’re Using Today
The Basic Commands
The Basic Commands
The Basic Commands
The Basic Commands
Commands We’re Looking at Today
Clone a Repo
Fork and Clone the Example Repo
Create a Local Copy of the Git Repository
Create/navigate to where you want to store your repo� $ mkdir ~/src� $ cd ~/src�Configure your git username and email—this step is required to make commits� $ git clone THE_URL_YOU_COPIED� $ cd fixing_git
Create a file you want to be added to the original repo
Create a branch� $ git branch BRANCHNAME� $ git checkout BRANCHNAME�Create a file in a text editor or just type� $ echo wow this is a nice message >> myFile.txt�Add the file� $ git add myFile.txt
Commit the file� $ git commit -m "Add myFile.txt"
Push the commit� $ git push
Create a Pull Request
Head to github repo that you forked
Click the “New Pull Request” button
SELECT the_wild_west on the base repo
When approved it will be a part of the example repo
Let’s continue
Checkout master� $ git checkout master
Concepts
DAG: Directed Acyclic Graphs
in other words “non-time-travelling Royal family rules”
All Commits Are Nodes in a Single DAG
Branches Are Not Places
Everything in Git is a Commit
Situations
Following along is encouraged
Situation 1 - Branch Named Incorrectly
Let’s list all of our branches
$ git branch
It looks like the person who made the repo �named the “dev” branch “deb”�1. Create a new branch called dev that �points to where deb does currently
$ git branch dev deb
$ git checkout dev
2. Delete the old branch
$ git branch -D deb
Situation 2 - Committed on the Wrong Branch
Situation 2 - Committed on the Wrong Branch
Let’s mess this up ourselves
$ git checkout master� $ echo some words > some_file� $ git add some_file� $ git commit -m "add some_file"� $ echo some more words >> some_file� $ git add some_file� $ git commit -m "add more to some_file"� $ git log --oneline --decorate --graph --all�
Situation 2 - Committed on the Wrong Branch
Situation 2 - Committed on the Wrong Branch
master
HEAD
???
HAVE
WANT
7db37e4
"add some_file"
"add more to some_file"
7db37e4
"add some_file"
"add more to some_file"
Situation 2 - Committed on the Wrong Branch
7db37e4
"add some_file"
"add more to some_file"
master
HEAD
7db37e4
"add some_file"
"add more to some_file"
master
HEAD
someNewBranch
HAVE
WANT
Situation 2 - Committed on the Wrong Branch
Create a new branch pointer at our latest commit
$ git branch someNewBranch master
Point HEAD to our new branch
$ git checkout someNewBranch
Forcefully point the wrong branch back to where we want it
$ git branch --force master 7db37e4
Situation 2 - Committed on the Wrong Branch
Key Takeaways
Branches are pointers, not places
It’s better to have an amazing understand of the core commands than to know many commands
Every commit that ever existed still exists
Git hates you but it will always keep committed work
There’s no shame in recloning, just save your work
Sources
https://nathanhoad.net/how-to-undo-git-commit/
https://nathanhoad.net/how-to-git-stash/
https://www.reddit.com/r/learnprogramming/comments/al0ebi/anyone_got_an_eli5_version_for_basic_git/
https://blog.scottnonnenberg.com/better-git-configuration/
https://hackernoon.com/lesser-known-git-commands-151a1918a60
https://www.alexkras.com/19-git-tips-for-everyday-use/#auto-complete
https://www.reddit.com/r/programminghorror/comments/23qnxx/best_alias_ever_git_fuck/
https://medium.com/thefloatingpoint/give-github-desktop-a-chance-7cea7d4f0d37
https://davidjcastner.github.io/git-tutorial/Lab3 �https://en.m.wikipedia.org/wiki/Directed_acyclic_graph
https://www.atlassian.com/git/tutorials/what-is-git�https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell
https://product.hubspot.com/blog/git-and-github-tutorial-for-beginners
https://github.com/Ry4an/unbreaking-git
�
Thank You
Now Git Out