This is a simple Git cheat sheet. Most usage Git command lines are included.
Basic workflow
git init
create new repository git clone /path/to/repository
clone local repository git clone [email protected] :/path/to/repository
clone remote repository git add <filename>
add changes of a file git add *
add all changes git rm <filename>
delete a file git commit -m *<comment>*
commit changes git push origin naster
push changes to remote repository git remote add origin <server>
connect local repository to remote one git pull
update local repository with remote one
Branches
git branch
List all local branches git branch -a
List remote and local branches git checkout -b <branch_name>
Create a new local branch and switch to it git checkout <branch_name>
Switch to a branch git push origin <branch_name>
Push a branch to remote git branch -m <new_brand_name>
Rename a branch git branch -d <branch_name>
Delete a local branch git push origin <branch_name>
Delete a remote branch
Clean up
git clean -f
Delete all untracked files git clean -df
Delete all untracked files and directories git checkout -- .
Undo local modifications to all files git reset HEAD <filename>
Unstage a file
Stash
git stash save "<stash_name>" && git stash
Save changes to a stash git stash list
List all available stashes git stash pop
Delete a stash from the list
Log
git log --oneline
Show commit history in single lines git log -10
Show commit history for last 10 commits git log -p -10
Show commit history for last 10 commits with diff git diff
Show all local file changes in the working tree git diff <filename>
Show changes made to a file git blame <filename>
Show who modified a file git remote show origin
Show remote branches and their mapping to local