Slide 1

Slide 1 text

Mastering Git CLI Part One

Slide 2

Slide 2 text

…is and is not • is a technical talk • is not an introduction to version control or git

Slide 3

Slide 3 text

Assumptions • Comfortable with basic bash commands • Already using version control (specifically git) • Familiar with git concepts and terms

Slide 4

Slide 4 text

tl;dr (or listen) git --help git [command] --help

Slide 5

Slide 5 text

Configuration & Set Up

Slide 6

Slide 6 text

Git Configuration User-specific configuration file (aka “global”) $ git config --global color.ui auto ~/.gitconfig [project-path]/.git/config Project-specific configuration file (overwrites global options)

Slide 7

Slide 7 text

User Set Up Configure your user information $ git config --global user.name "[name]" $ git config --global user.email "[email]" This information is used to “author” your commits IMPORTANT:
 The commit email address is used to attribute commits to your GitHub user. Make sure you add your email address to your GitHub profile.

Slide 8

Slide 8 text

User Set Up Configure your user information $ git config --global user.name "[name]" $ git config --global user.email "[email]" This information is used to “author” your commits [user] name = Andrew Turner email = [email protected] ~/.gitconfig

Slide 9

Slide 9 text

Misc Options Colorize CLI output $ git config --global color.ui auto Autocorrect typos WARNING: You called a Git command named 'statis', which does not exist. Continuing under the assumption that you meant 'status'... $ git config --global help.autocorrect 1

Slide 10

Slide 10 text

Misc Options Git Aliases $ git config --global alias.s status $ git config --global alias.a add $ git config --global alias.co checkout $ git config --global alias.last 'log -1 HEAD' $ git config --global alias.unstage 'reset HEAD --' [alias] s = status a = add co = checkout last = log -1 HEAD unstage = reset HEAD ~/.gitconfig

Slide 11

Slide 11 text

Basic Commands

Slide 12

Slide 12 text

Getting Started Cloning an existing repository Creating a new repository $ git clone [project-name] Duplicate a existing repository in your current working directory $ git init [project-name] Initializes a new git repository in your current working directory

Slide 13

Slide 13 text

Getting Started Creating branches $ git branch Creates a new branch from your current HEAD, but does not activate it $ git checkout -b Creates a new branch from your current HEAD and makes it your active branch Switching to an existing branch $ git checkout Sets your working directory to the the specified branch name

Slide 14

Slide 14 text

Doing Work View status of repository and files On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git commit -a") $ git status ## master…origin/master M README.md $ git status -sb

Slide 15

Slide 15 text

Viewing Changes (diff) diff --git a/README.md b/README.md index dfa025c..2de90d0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ npm install npm run init-project ``` -_The `init-project` command checks for docker dependancies, creates a new docker-machine VM (if it doesn't exist), sets a local `.host` file with the docker machine's IP address, and builds the docker images._ +_The `init-project` command checks for docker dependencies, creates a new docker-machine VM (if it doesn't exist), sets a local `.host` file with the docker machine's IP address, and builds the docker images._ ### Running the Application To start the application, simply run the following command: $ git diff [path|file] See what code has changed

Slide 16

Slide 16 text

Viewing Changes (diff) diff --git a/README.md b/README.md index dfa025c..2de90d0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ npm install npm run init-project ``` -_The `init-project` command checks for docker dependancies, creates a new docker-machine VM (if it doesn't exist), sets a local `.host` file with the docker machine's IP address, and builds the docker images._ +_The `init-project` command checks for docker dependencies, creates a new docker-machine VM (if it doesn't exist), sets a local `.host` file with the docker machine's IP address, and builds the docker images._ ### Running the Application To start the application, simply run the following command: $ git diff [path|file] diff --git a/README.md b/README.md index dfa025c..2de90d0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ npm install npm run init-project ``` _The `init-project` command checks for docker [-dependancies,-]{+dependencies,+} creates a new docker-machine VM (if it doesn't exist), sets a local `.host` file with the docker machine's IP address, and builds the docker images._ ### Running the Application To start the application, simply run the following command: $ git diff --word-diff [path|file]

Slide 17

Slide 17 text

Saving Work Stage files $ git add [path|file] Adds files to the index (will be included in next commit) $ git add -i Interactively stage files or parts of a file Unstage files $ git reset HEAD -- [path|file] Removes files from the index (will not be included in next commit)

Slide 18

Slide 18 text

Saving Work Commit changes # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Your branch is up-to-date with 'origin/master'. # # Changes to be committed: # modified: README.md # $ git commit $ git commit -m 'an awesome commit message'

Slide 19

Slide 19 text

Sharing Work Push changes to existing remote branch Push new branch to remote $ git push origin [branch] $ git push -u origin [branch] Tip: -u is shorthand for --set-upstream

Slide 20

Slide 20 text

Getting Other’s Work See if there are new commits Check for new commits and merge into current branch $ git fetch origin [branch] $ git pull origin [branch] This does not get the changes, just checks for new commits

Slide 21

Slide 21 text

Additional Resources • Try Git (15 minute in-browser tutorial)
 https://try.github.io • Git Documentation (…not RTFM)
 https://git-scm.com/documentation • Git Cheat Sheet (PDF)
 https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf • Visual Git Commands (interactive)
 http://ndpsoftware.com/git-cheatsheet.html • Git & GitHub Secrets (presentation from Zach Holman)
 https://speakerdeck.com/holman/git-and-github-secrets • Slides to this deck
 https://speakerdeck.com/galenandrew/mastering-git-cli-part-one

Slide 22

Slide 22 text

Thank you!