A list of common and / or useful git related commands
Action | Command |
Help on any git command: | git <command> –help |
List modified and staged files: | git status |
View diff on modified file: | git diff file.cm |
View diff on staged file: | git diff –staged file.cm |
View diff between commits: | git diff 8fef..c6e7 (replace hash numbers) |
View commit log: | git log |
View last three commits and their diffs: | git log -n3 -p |
View without merge commits | git log –no-merges |
Stage a file: | git add file.cm |
Unstage a file: | git reset HEAD file.cm |
Undo all unstaged and staged files: | git reset –hard |
Undo last commit (do not do this on pushed commits) | git reset –soft HEAD^ |
Remove a file: | git rm file.cm |
Rename or move a file/folder: | git mv file.cm newFile.cm |
Commit staged files | git commit |
Change last commit message: | git commit –amend |
Undo changes to file: | git checkout – file.cm |
Create and switch to new branch: | git checkout -b mine/newbranch |
Switch to branch: | git checkout mine/newbranch |
Create a new branch: | git branch mine/newbranch |
List all local branches: | git branch |
List all remote branches: | git branch -r |
List all branches: | git branch -a |
Delete merged branch: | git branch -d mine/newbranch |
Delete unmerged branch (data will be gone): | git branch -D mine/newbranch |
Stash uncommitted changes | git stash |
Unstash and remove stash | git stash pop |
Unstash and keep stash | git stash apply |
Drop stash | git stash drop |
List stashes | git stash list |
Unstash and keep the third stash | git stash apply stash@{2} |
Merge version9.5 into mine/newbranch: | git checkout mine/newbranch git merge version9.5 |
Push a local branch to remote: | git push -u origin mine/newbranch |
Delete a remote branch: | git push –delete origin mine/newbranch |
Create an annotated tag & push it to remote: | git tag -a v9.5.1 -m "My v9.5.1 tag" git push origin v9.5.1 |
Delete a local tag: | git tag –delete v9.5.1 |
Delete a remote tag (please don't): | git tag –delete origin v9.5.1 |
Remove deprecated remote tracking branches | git remote prune origin |
Change commit message editor to notepad | git config –global core.editor notepad |
Make fast-forwarding merges disabled by default | git config –global –add merge.ff false |
Resolve merge conflicts with mergetool | git mergetool |
Comments
0 comments
Please sign in to leave a comment.