Skip to content
Mike Schechter edited this page May 23, 2013 · 3 revisions

Pro Git

Fork A Repo Doc - https://help.github.com/articles/fork-a-repo Step 3: "Configure remotes" is key for knowing how to pull/push from/to a forked repo.

GIT quick guide notes from GIT REAL video. I tried to get everything lined up so you can see the options with each call. As we learn more ways to use GIT lets keep this updated.

git config --global user.name "NAME" (Sets name to NAME) *without --global these setting will not be set as the default.

                        user.email  (sets email to EMAIL)
                        color.ui true    (colors the commit line in log)
                        core.editor emacs (use emacs for interactive commands)
                        merge.toll opendiff (uses opendiff for merging conflicts)
                        alias.mylog \  "log --pretty=format:'%h %s [%an]" --graph (makes a custom log setting usable through git mylog)
                        alias.lol \ "log --graph --decorate --pretty=oneline --abbrev-commit --all"   (example lol log alias)
                        alias.alias command (makes an alias for any command.  Then is used with git alias)
            --list  (lists configurations)
            user.email (displays how these things are configured)

git init (makes a local repository in current directory

git add "name of file' (stages file)

      foo.txt bar.txt foobar.txt  (list of files  I don't remeber if this need ',' between files)
     --all
     *.txt (all .txt files in current dir)
     docs/*.txt (all txt files in doc dir)
     docs/   (all files in doc dir)
     ".txt"   (all .txt file in whole project)

git status (what changed since last commit)

git commit -m "description" (commits all staged files)

       -a -m "message"  (adds and commits tracked files at once)
       --amend -m "message" (amends last commit with additional files--RUN BEFORE PUSH)

git log (lists commits with description)

     --pretty=oneline (gives you one line log with SHA and  	commit message)
             =format: "%h %ad- %s [%an]"   (%h ect. are placeholders- you're choosing what items to be shown in the log  See below for more extensive list)
     --oneline -p  (shows the lines that were removed or added )
                  -stat (how many insertions and deletions for each file in each commit))
                  --graph ( visual representation)
     --until=1.minute.ag
     --since=1.day.ago
     --since=1.month.ago --until=2.weeks.ago
     --since=2012-01-03 --until=2013-4-20
  Option  Description of Output-    %H  Commit hash      %h  Abbreviated commit hash      %T  Tree hash       %t  Abbreviated tree hash     %P  Parent hashes     %p  Abbreviated parent hashes    %an Author name    %ae Author e-mail     %ad Author date (format respects the --date= option)     %ar Author date, relative       %cn Committer name     %ce Committer email    %cd Committer date   %cr Committer date, relative        %s  Subject

git diff (lists all differences since last commit, unstaged differences)

     --staged (differences in staged items)
     HEAD  (diff from last commit and current state)
     HEAD^^ (2 commits ago)
     HEAD~5 (five commits ago)
     HEAD^..HEAD (compares 2nd most recent commit with current state)
     (can also use branches, SHA's or time for diff)

git blame fileName (displays commit hash, author, date of commit, line# and content)

git reset HEAD FILENAME (unstages filename) (DO THESE BEFORE PUSH)

      --soft HEAD^   (undoes last commit, moves last commit to staging)
      --hard HEAD^  (completely 'blows away' the last commit.  additional ^'s go back more steps

git checkout --FILENAME (restores file to previous state)

git remote add origin http://URL (origin=name, URL= address)

             -v (shows what remotes repo knows about)
             -rm name (removes remote)
             show origin (origin=remote: shows remote branches, local branches,  and their status)
             prune origin (removes 'stale references' if someone deleted a branch from remote that you still had locally)

git push -u origin master (origin=remote master=branch pushes branch to remote)

       (-u sets it so that remote is where you will push to until changed)
       origin name   (pushes local branch to remote so it can be tracked and pulled by other users)
       origin :name  (origin=remote, name=branch  deletes branch from origin)

git pull (pulls changes from remote and syncs with local repo) makes sure you have latest changes

git clone http/URL NAME (clones repo to local machine, name optional only to have a different name

                    (creates remote called origin pointing to source)
                    (checks out branch (probably master, and sets the HEAD)

git branch name (creates new branch named name) eg. of types of branches -master (default) bug-fix, feature

            (lists current branch)
            -d name  (deletes branch 'name')
            -D name (deletes branch even if not merged error)
            -r  (list remote branches, not just local ones)

git checkout name (switches to branch name)

             -b name (creates and checks-out branch at once)

git merge name (merges branch 'name' to Master)

git tag (lists tags- used for versions releases or 'benchmarks)]

    -a name "description"   (adds new tag name and description)
    checkout tagName   (goes to tag)
    push  --tags (pushes tags to remote)

git rm fileName (removes file or folder from repo)

   --cashed  fileName   (stops tracking file deletes it, but not from your system))

REBASING

git fetch (pulls but doesn't merge)

git rebase (1st moves all changes from master in 'temp' area, 2nd runs origin/master commits 3rd temp area changes are commited)

 after confflict   (fix conflicted file, add file, rebase --continue to continue)
             --continue   (after conflict resolved))
             --skip     (skip patch)
             --abort   (undoes rebase and checksout original branch

Excluding

(Put and files you want to exclude in folder .git/info/exclude) .gitignore

       cat file (concatenates file)
       cat .gitignore /n path/file (adds files to ignore .gitignore file)
Clone this wiki locally