iax7
11/15/2017 - 5:01 PM

GIT

GIT Cheatsheet

GIT

Reset

https://www.websequencediagrams.com/
participant HEAD
participant Index
participant WorkingTree

HEAD->WorkingTree:checkout
WorkingTree->Index:add
Index->HEAD:commit

   HEAD       Index     WorkingTree
    |           |             |
    o------- checkout ------->o
    |           |             |
    |           o<--- add ----o
    o<--commit--o             |
    |           |             |
   soft
   mixed      mixed
              hard          hard
  • --soft leaves index file & WorkingTree untouched. Undoes the last commit you made.
  • --mixed resets index but not WorkingTree (default). You rolled back to before you ran all your git adds AND git commit
  • --hard resets index & WorkingTree

Git ignore

  • .git/info/exlude --> private repo ignore file
  • .gitignore --> per directory and his subdirs... SHARED

.gitignore

  /dirname/    --> only directory ignore
  */dirname/   --> this dir in any subdir
  /*.extension --> this extension
  filename.ext --> this file only

Git Clone Step by Step

  1. git init

  2. git remote add origin <URL>

    origin is default name Creates an alias for the URL

  3. git fetch --no-tags origin master:refs/remotes/origin/master

    master name of the remote branch in the remote repo refs/remotes/origin/master is local path; The name of the remote tracking branch, local branch in remote's

  4. git branch master origin/master

    master local branch equivalent to --set-upstream-to=master

    4.1. git rev-parse origin/master > .git/refs/heads/master

    or equivalent command: cp .git/refs/remotes/origin/master .git/refs/heads/master

    4.2. git branch --set-upstream-to=origin/master

    Sets local branch to track the remote branch stored in refs/heads/master

    Equivalent commands:

    • git config branch.{branch_name}.remote origin
    • git config branch.{branch_name}.merge refs/heads/{remote_branch_name}
  5. git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master

    This is how we know which branch is default in the remote end. refs/remotes/origin/HEAD creates local file HEAD refers to refs/remotes/origin/master

  6. git checkout