Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mastering Git CLI - Part One

Mastering Git CLI - Part One

Part One of a series covering Git CLI

Andrew Turner

January 27, 2016
Tweet

More Decks by Andrew Turner

Other Decks in Programming

Transcript

  1. …is and is not • is a technical talk •

    is not an introduction to version control or git
  2. Assumptions • Comfortable with basic bash commands • Already using

    version control (specifically git) • Familiar with git concepts and terms
  3. 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)
  4. 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.
  5. 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
  6. 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
  7. 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
  8. Getting Started Cloning an existing repository Creating a new repository

    $ git clone <url> [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
  9. Getting Started Creating branches $ git branch <new-branch-name> Creates a

    new branch from your current HEAD, but does not activate it $ git checkout -b <new-branch—name> Creates a new branch from your current HEAD and makes it your active branch Switching to an existing branch $ git checkout <branch-name> Sets your working directory to the the specified branch name
  10. 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 <file>..." to update what will be committed) (use "git checkout -- <file>..." 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
  11. 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
  12. 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]
  13. 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)
  14. 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'
  15. 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
  16. 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
  17. 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