Git
Git stores everything in a directory, rm -rf .git
to delete the git project
git --help command
Changing History
Reflog
Saves every instance of head changes
Get specific file from past
Rebase
rewrites history, if commits not local can mess things up
could also rebase all your branch commits to occur at end of current master to avoid a merge commit
git rebase master
, rebases current branch to master one
Merge master in your branch before push
git pull --rebase origin master
Squash many commits to one
git rebase -i <COMMIT_TO_IGNORE>
S
quash all but topquit-save to rebase
Stash
git stash
- Takes dirty changes and saves them without committing
git stash pop
- Reapply last saved changes
git stash apply stash@{2}
Undoing Last Commit
git reset --hard HEAD~1
=> don't keep changes
git reset --soft HEAD~1
=> undo commit, but keep working changes
git revert <commit to undo>
=>Commit a commit undoing last commit
Remotes
git remote -v
=> List origins
Add remote
git remote add origin [github url]
Selecting branch to push from and to
Reset to remote branch
git checkout -B master origin/master
//-B resets if it already exists
Other
List Branches By Last Modified
Tagging
git tag -a v1.4 -m "my version 1.4"
Delete branches
git branch -d <branchname>
git remote prune origin
//remove all branches not in origin
Stop tracking file
git rm --cached <file>
Remove all Untracked files and build products
git clean -fd
//remove everything untracked besides what is ignored by .gitignore git clean -fdx
//remove all untracked files including those ignored by .gitignore git clean -fdX
//only remove files ignored by .gitignore
Find commit that broke it
Git grep
git grep [string]
find all lines tracked by the git repo with the given string
git grep -n -C 3 TeachApp
Modifiers:
-n
: show line numbers-C 5
: show 5 context lines before and after-i
: ignore case
Git Ignore
Git LFS(Large File Store)
Basically, lets you use large files in github by using fileptrs
Setup
brew install git-lfs
Track like
git lfs track "*.psd"
or have.gitattributes
.gitattributes
Thats it, just use normal workflow
Other people
git lfs install
to get huge assetsgit lfs pull
to get lfs
Last updated