Last active
August 29, 2015 14:05
-
-
Save vienhoang/63a4b147bbe266adbddd to your computer and use it in GitHub Desktop.
Git: Commands, Unix
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
Working in terminal | |
cd | Change directory | |
ls | List directory | |
ls -al | List all files with permissions showned | |
mv | Change file name, mv #filename1 #filename2 | |
mv * .. | Move everything up one directory | |
rm | Remove file, rm #filename | |
wget | Download a file, wget #filelocation | |
tar --xzvf | Extract .gz file, tar --xzvf #filename | |
tar -cvf | Compress | |
pwd | Show current location, print working directory | |
cp -R | Copy site recursively, cp -R #temp/sites/ #website | |
touch #filename | Make a new file | |
Nix Shortcuts | |
* | Everything | |
. | Current location | |
.. | Level above | |
~ | Home directory | |
/ | Show directory structure | |
--- | |
Git | |
git init | initialize | |
git add . | add files | |
git add #folder/ | add everything in that folder | |
git commit -m "message" | commit | |
git log | show log messages | |
git log -n | show number of logs | |
git log --since=2013-10-01 | |
git log --until=2013-10-01 | |
git log --author="Vien" | |
git log --grep="Init" | show log with regexp | |
git diff | show difference between files between working directory and repository | |
git diff --staged | check difference staged directory and repository | |
git diff --color-words | color words | |
git diff #startsha1..#endsha1 -- #filename | Make sure that you get the 1 commit before the startsha1 if git return nothing. | |
Simply make sure that you're fetching the correct start and end sha1. | |
git rm #filename | remove file | |
git mv #filenmae #filname2 | rename the file and add it to staging dir | |
git commit -a | commit and add, grab everything ONLY for commit modification, not include deleted files | |
git checkout -- #filename | checkout filename | |
git checkout #sha1 -- #filename | check out filename with sha1 to staging dir | |
git reset HEAD #filename | reset staged changes | |
git commit --ammend -m "message" | modify gitrepository without adding an extra commit, modify HEAD commit | |
git revert sha1 | revert the repository it previous and make a commit of it | |
git reset --soft #sha1 | |
git reset --mixed(default) #sha1 | |
git reset --hard #sha1 | |
git log --oneline | show log one line per commit | |
git log --format=online | |
git log --format=short | |
--format=medium | |
--format=full | |
git log --graph | |
git log -p | show patch, show detailed changes | |
git log --stat --summary | show stats of commits | |
git clean -n | test clean run | |
git clean -f | clean the untracked files | |
notepad .gitignore | create a git ignore file with notepad | |
git rm --cached #filename | remove from staging index | |
git show #sha1 | show the commit | |
git show --format=oneline HEAD~3 | show 3 commit back form the HEAD | |
git diff #sha1..#sha1 | |
git branch | show branches | |
git branch #name | create new branch | |
git checkout -b #branchName | create and immediately switch to a branch | |
git checkout #newbranch | checkout the new branch | |
git diff #master..#newbranch | show diff between branches | |
git diff --color-words #master..#newbranch | show diff in branches with colors | |
git branch --merged | compare if the current branch is merged from any other branch | |
git branch -m #oldbranch #newbranch | rename branch | |
git branch -d #branch | delete branch | |
git branch -r | show remote branch | |
git branch -a | show all branch include remote | |
git merge #targetbranch | merge with the targeted branch, fast forward merged, master no new commit after branching, must be on the old branch first | |
git merge --no-ff #branch | make new commit, no fast forward merge | |
git merge --ff-only branch | do the merge only if it can do fast forward else abort | |
git stash save "message" | save a stash so you can have the changes saved and checkout differenct branch | |
git stash list | list all stasches | |
git stash show stash@{0} | |
git stash show -p stash@{0} | show differences | |
git stash pop stash@{0} | pop stash item to working dir and remove | |
git stash apply stash@{0} | take out item from stash and apply | |
git stash drop stash@{0} | drop the stash item | |
git stash clear | clear out stash | |
git remote | show all remotes | |
git remote add origin #githubURL | add new remote github | |
git push -u #alias master | push up to remote repo and keep tracking | |
git remove rm #origin | remove remote branch | |
git rm -r #folderName | remove folder | |
git clone #githubURL #name | |
git fetch | fetch from remote repo | |
fetch before you work | |
feth before push | |
fetch often | |
git pull = git fetch + git merge | |
git branch #remotebranch #localbranchname | get remote branch | |
git checkout -b #remotebranch #localbranchname | checkout remote branch | |
git push origin --delete #remotebranch | delete remote branch | |
--- | |
Work flow | |
git init | |
git add . | |
git commit -m "message" | |
git remote add origin #githubURL | |
git fetch | |
git merge origin/master | merge with the local fetch repo | |
git push -u origin master | push up to remote repo from master(working dir) | |
---- | |
push to github | |
git push -u origin master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment