git init - Sets up new repo in current directory
git remote add origin https://github.com/user/repo.git - Add a remote repo like bitbucket
git status
git config --global color.ui true - Add color to output for better readability
git config --global user.name - Change username
git config --global user.email - Change email address
git config --global merge.tool opendiff - set diff custom diff tool
git config --global alias.co checkout - creates a shortcut for checkout called co, git co
git log
git log --pretty=oneline
git log --pretty=oneline -p - for patch output to see what lines were removed and added
git log --pretty=format:"%h %ad- %s [%an]"
git log --global alias.mylog or alias.lol then just use git mylog or git lol
git log --online --graph -Shows branches and commits on them
git log --until=1.minute.ago
git log --since=1.day.ago
git log --since=1.month.ago --until=2.weeks.ago
git log --since=2000-1-1 --until=2012-12-21
git add
git commit
git commit -a -m 'Comment'
git commit --amend -m 'Comment' - Will amend previous commit with whatever is on staging.
git push - Puts files on remote server. The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do.
git push origin
git push origin :
git pull origin master - Get changes from remote location (origin)
git diff HEAD - Show diff of changes by others.
git diff HEAD^ - Parent of latest commit
git diff HEAD^^ - grandparent of latest commit
git diff HEAD~5 - five commits ago
git diff HEAD^..HEAD - second most recent commit vs most recent
git diff sha..sha - compare by sha1 hash of two different commits
git diff branch1 branch2 - compare branches
git diff --since=1.wee.ago --until=1.minute.ago
git diff --staged
git reset
git reset --soft HEAD^ - undoes the last commit
git reset --hard HEAD^ - undoes the last commit and deletes the files from staging
git checkout --
git branch
git branch - Shows all the branches
git branch -r - Shows all remote branches on the repo
git checkout
git checkout -b
git branch -d
git rm
git rm --cached
git merge
git help
git clone
git remote -v - lists all the origins
git remote show origin - Shows all the remote branches and if they are tracked
git remote prune origin - Cleans up any deleted branches from the repo
git tag - list all tags
git checkout
git push --tags - Push them to the remote repo
git rebase
git rebase --continue
git blame
Exclude files/folder by adding name to .git/info/exclude
Exclude by pattern as well, *.mp4, logs/*.logs, etc.
Use .gitignore for ignoring log files.
git rebase -i HEAD~3 - redo last three commits
git stash apply - gets the saved files
git stash list - displays all the stashed code
git stash show stash@{0} - shows details of one particular stash
git stash show --patch - shows the file diffs
git stash apply stash@{1} - gets the stashed code at position 2
git stash drop - to remove from the list
git stash pop - runs both git stash apply and get stash drop
git stash save - saves modified files, restores last commit
git stash save "add optional comment"
git stash save --keep-index - causes the staging area not to be stashed
git stash save --include-untracked - causes untracked files to be stashed too
git stash branch
git stash clear - clears away the stash list
-- Deleting History --
git filter-branch --tree-filter 'rm -f
git filter-branch -f --prune-empty -- --all - Drops empty commits that don't alter any files
-- Line Ending --
git config --global core.autocrlf input - For Unix based systems
git config --global core.autocrlf true - For Windows
-- Cherry Picking --
git cherry-pick
git cherry-pick --edit
git cherry-pick --no-commit
git cherry-pick -x
git cherry-pick --signoff
git submodule add
cat .gitmodules - Shows contents of the file
git submodule init
git submodule update
git merge
** Push twice when editing submodules.
git push --recurse-submodules=check
git push --recurse-submodules=on-demand - Force submodules to be pushed with the master branch is pushed.
git config alias.pushall "push --recurse-submodules=on-demand" -Creates shortcut to alwasy push submodules.
-- Reflog --
Restore deleted commit.
git reflog - Shows local copy of log for all actions
git reset --hard
git log --walk-reflogs - Gives greater detail for commits
git branch
No comments:
Post a Comment