=============
= Git setup =
=============
git config --global user.name "Your Name"
git config --global user.email your.email@example.com
git config --global push.default matching #ensure forward-compatibility with upcoming releases of Git
git config -l = show list of git configurations
===========
= Aliases =
===========
subl .gitconfig #see all git aliases (must do from home directory)
git config --global alias.co checkout #alias co checkout
git config --global alias.cob "checkout -b" #allias checkout branch
git config --global alias.cm "commit -m" #alias commit message
git config --gbloal alias.dif diff #alias diff
git config --global alias.s status #alias status
git config --global alias.br "branch -v" #alias branch version
git config --global alias.l "log --oneline" #alias log --oneline
git config --global alias.hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short" #alias history
==================================
= How to undo major coding error =
==================================
# File has been deleted, but only on the “working tree”; they haven’t been committed yet
# Undo the changes using the checkout command with the -f flag to force overwriting the current changes:
git add .
git checkout -f
====================
= Console commands =
====================
git remote -v = list all remotes of github repo
git add . = add all files to github staging area
git commit -m "[message]" = commit local repo changes with [message]
/*** if branch exists on local but not github ***/
git push -u [repo] [branch] = map local branch to [repo][branch] & push local repo commits (local & repo branches must have same name)
/*** if branch doesn't exist on github or local ***/
git push [repo] [local branch]:[remote branch] = create [github] branch (if non-existent)/connect local branch to [github] branch
= example: git push origin master:feature/carrierwave, then you must checkout to that branch
/*** if branch exists on github but not local ***/
git checkout -b [name] [repo][branch] = on local, create non-existent branch [name] & track [repo][branch]
= example: git checkout -b fix/db origin/fix/db
/*** reaname branch locally & remotely ***/
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
git fetch origin = fetch origin & pull all branches
git checkout [name] = checkout to existent branch
git branch -v = list all local branches & most current commit
git branch -a = list all branches on local & remote
git branch -d [name] = delete branch [name] (must not be on that branch)
git checkout -- [filename] = revert changes on [filename] on local repo
git reset --hard HEAD = rever 1 commit on all files & unstage changes
git reset HEAD [filename] = revert 1 commit on [filename]
git stash = save (stash) changes for later (but not commit) then revert code back prior to stash
git status -s = git status short format
git status -s | sed 's/?? //' | xargs rm -r = revert all changes on local repo (master nuke)
git log --oneline = show oneline log of commits
git diff [branch1]...[branch2] = compare differences between branch1 and branch2
= example: git diff --staged