Skip to content

Instantly share code, notes, and snippets.

@nfet
Last active August 29, 2015 14:00
Show Gist options
  • Save nfet/11013504 to your computer and use it in GitHub Desktop.
Save nfet/11013504 to your computer and use it in GitHub Desktop.
Git Notes
Add Git Notes Here
[alias]
diff-last = diff HEAD^1
lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
Create New Local Repository
%> mkdir [new-project]
%> cd [new-project]
%> git --bare init
Initially Push to Remote
%> git remote add origin [url]
%> git push -u origin master
# Log with graph
%> git log --graph
# Log remote
%> git log origin/master
%> git log origin/[branch]
# Diff Against Remote Origin
%> git diff --stat origin/master
# Diff Against a Remote Branch
%> git branch -a
%> git diff --stat origin/[branch]..origin/master
OR
%> git diff --stat remotes/origin/[branch]..origin/master
# Add Origin
%> git remote add origin
# Add Upstream
%> git remote add upstream [url]
# Show Remotes
%> git remote show
# Show Remote Origin/Upstream
%> git remote show origin
%> git remote show upstream
# Change Origin
%> git remote set-url origin <new-url>
%> git remote show origin
# Create Branch & Checkout
%> git checkout -b [mybranch]
# Push Branch to remote for the first time
%> git push -u origin [mybranch]
# Push a local branch to a remote branch
%> git push origin [localbranch]:[new_remote_branch]
# Delete a remote branch
%> git push origin :[branch_to_delete]
# Checkout a remote branch
%> git fetch or git pull
%> git checkout -b [new_branch_name] origin/[branch_name]
# Reset and still indexed (added) previous commits (keep commits)
%> git reset --soft //head
%> git reset --soft [hash]
# Reset and un-index previous commits (keep commits)
# Previous commits are rolled up
%> git reset --mixed // head
%> git reset --mixed [hash]
# Reset and delete previous commits (HEAD)
%> git reset --hard // head
%> git reset --hard <hash>
# Revert previous commit (in master)
%> git fetch or git pull
%> git reset --soft HEAD^ //resets to previous commit
%> git push origin master --force
# Revert to a hash (in master)
%> git fetch or git pull
%> git reset --soft <hash>
%> git push origin master --force
# Roll up previous commits (in branch)
%> git fetch or git pull
%> git reset --mixed <hash>
%> git add -A && git commit -m "rolled up into one"
%> git push origin [branch_name] --force
SEE ALSO:
http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment