-
-
Save jeffschulthies/22f54622368551d0a90a4252215ddeca to your computer and use it in GitHub Desktop.
git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git log --oneline | |
git status -s | |
Configuration Levels | |
System | |
- Multiple users log into the same box. Build box | |
Global | |
Local | |
~/.gitconfig | |
git config --global user.name "Jeff Schulthies" | |
git config --global user.email "jeffschulthies@gwu.edu" | |
# Removes carriage returns | |
git config --global core.autocrlf input # Mac/Linux | |
git config --global core.autocrlf true # Windows | |
git config --global alias.s "status -s" | |
git config --global alias.lg "log --oneline --all --graph --decorate" | |
git rm --cached [file] | |
Removes the file from version control but preserves the file locally | |
git config --global core.excludesfile ~/.gitignore | |
Git Ignore | |
.gitignore | |
*.log # This ignores all the log files | |
!special.log # Don't ignore this one | |
Branches | |
git branch -d [name] | |
git checkout -b [name] # create and checkout a branch | |
Merge | |
git merge --no-ff | |
Diff | |
git diff --staged | |
git diff HEAD | |
Rebase | |
git rebase master | |
# Pulling from master where there is a merge conflict | |
git rebase origin/master | |
git pull --rebase | |
Rebase Interactive -i | |
git rebase -i HEAD~5 | |
# Common workflow -> Usually squash them | |
Instead of pick | |
Use f -> f rolls the last commit into the latest one (the one on top) | |
r -> reword | |
Tags | |
git tag v1.0.0 | |
git tag -a v1.0.0 -m "message" -> Default one | |
git tag -s | |
git push --tags | |
Cherry Pick | |
# takes a commit and you're able to apply them to multiple branches | |
git cherry-pick sha1-hash | |
git cherry-pick -n sha1-hash -> Don't merge | |
Stash | |
git stash | |
git stash apply | |
git stash pop | |
Revert | |
git revert sha1-hash | |
Ammend | |
git commit --amend # You can also add files in the staging area | |
Reset | |
# Number of commits ago | |
git reset --soft HEAD~2 # Leave all the files in the staging area | |
git reset --hard HEAD~2 # Blows alway the files | |
git reset --mixed HEAD~2 # Default -> Unstages all the file | |
Reflog | |
# Keeps code in 30 days | |
git reflog # Get the sha1 hash of the commit | |
git reset --hard sha1hash # Bring the code to the point of the deleted code | |
git cherry-pick sha1hash # Bring back 1 code from the ether | |
git checkout sha1-hash # Look at reflog | |
git checkout -b temp_branch # Rebase or merge -> git rebase master | |
CLI Everything | |
https://hub.github.com/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment