Skip to content

Instantly share code, notes, and snippets.

@mstorino
Last active October 25, 2017 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstorino/9118b7e6ed44b939ec778c065d7c2666 to your computer and use it in GitHub Desktop.
Save mstorino/9118b7e6ed44b939ec778c065d7c2666 to your computer and use it in GitHub Desktop.
Git After It

Git Overview

Version control system where two directories are copies of each other, one ersion is a little more evolved than the previous one.

Over 100 commands

Basics:

Clone: This does 4 things 1) Create a new working directory (named after the repo server by deault), 2) initializes new git repo, 3) adds a remote called origin, 4) pull changes from the remote

  $~ git clone "gitrepo here"

Figure out what's going on with your repo

  $~ git status

Get rid of changes

  $~ git checkout /index.html

The prompt, current git branch listed in parenthese

  (master) $:

Branches: A virtual copy of your project, in isolation of the repo

Master: every Git repo starts with a master branch that Git assigns the name master by default. This is the primary stable version of your project

  (master) $: git branch
  * master

Create: Create and checkout branches. This will create a local branch and automatically check it out.

 $~ git checkout -b newbranchname

See all existing branches

  $~ git branch -a
  master 
  * newbranchname

Checkout an existing branch (LIKE MASTER)

   $~ git checkout branchname

Git Process

Phase 1: Keep your branch up to date with master. While working pull in the server's amster branch regularly, to reducte the risk of merge conflicts, and to help keep any conflicts that do occur as minimal as possible.

Git Pull: pull local commits from the remote repository

  $~ git pull origin master

Phase 2: Stage your changes. The staging area is not synced or shared with anyone on your team –– it only lives on your local machine

Add: add all (or specific) directories & files to the staging area Analogous to building a house

     $~ git add .
  
      $~ git add path/to/file/index.html

Commit: Record snapshot of the current state of your entire project. This is JUST A REFERENCE (like the way a street address refers to a house)

  $~ git commit -m "Commit Message Here"

Phase 3: Share your changes with the team

Git push: push local commits to the remote repository

  $~ git push origin master

Phase 4: Merge

Merge: Combine two (or more) different branches of your project into a unified version

Step 1: checkout the branch you want to merge to

     $~ git checkout master
     
Step 2: Merge

    $~ git merge branchname

Step 3: merge conflicts 
  Top conflict is version from current branch and bottom conflict is the one we're trying to merge in

Step 4: Staging change & telling git we've signed off on the current version
    
    $~ git add index.html 
    
    $~ git commit -m "merge branch master into newbranchname"



Step 5: Delete Branch

     $~ git branch -d branchname

Best Practices

Commit changes at regular intervals

Terminology

Fast-forward easiest kind of merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment