Git
git branch -vvcheck for remote repo connectiongit branch -r/-alist remote/all branchesgit branch -u origin/<branch>set the upstream branch for current branchgit blame <file-name>check for contributorsgit cherry-pick <commit1> <commit2> ...pick commits and append to current HEADgit config --global user.email "[email protected]"git config --global user.name "Your Name"git config --global alias.s statususegit sin short forgit statusgit config --global push.default simplegit config --global pull.ff onlygit config --global core.autocrlf true/false/inputgit config --global --unset <entry-name>unset global configurationgit clone -b <branch-name> --single-branch <url>git commit --amendre-commit the last commitgit checkout -go to previous branchgit checkout <branch>/<commit-id>/<tag>git checkout -b <branch>create a new branch and checkout to itgit checkout -b <branch> origin/<branch>also specify the upstream branchgit checkout <file-name>undo a file to the last commit (valid beforegit addthis file)git clean <file-name> -fremove untracked filegit clean <directory-name> -dfremove untracked directorygit clean -X -fremove files ignored by.gitignoregit diff --staged/cacheddiff between last commit and staged filesgit diff <id1> <id2>git diff <branch1> <branch2>git describe --tags --abbrev=0most recent tag in current branchgit log --graph --pretty=oneline --decorate --allgit push --forceforce update remote repo (overwrite commits in remote repo)git push origin masterwill push local master to remote master, regardless of current branchgit push origin <source>:<destination>push local source branch to remote destination branch wheresourcecould also be a location represented byHEAD~1ormaster^git push origin :foopush nothing to a remote branch foo will delete this branchgit fetch origin :foofetch nothing to a local branch foo will create this new branchgit pull= git fetch + git merge; two branches in historygit pull --rebase= git fetch + git rebase; a single line in history (recommended)git rm <file-name> -fremove a staged file and delete it from file systemgit rm <file-name> --cachedremove a staged file but still keep it in working directorygit reset <file-name>move a file from staging to working directorygit reset --hard/--soft/--mixed <commit-id>git remote -vto see the current remote URLgit remote set-url origin <newurl>reset URL for origingit revert <commit-id>go back to this commit by adding a new commitgit reflogsee all history operationsgit rebase <branch>merge into a single line by making copies of new commitsgit rebase -iinteraction mode (can pick commits)git stashgit stash list/pop/apply/drop/cleargit show <branch-name>:<file-name>git status --ignoredshow files ignored by.gitignoregit tag <name>git tag -lncheck for detailed infogit update-index --assume-unchanged <path/to/file>untrack/hide a filegit update-index --no-assume-unchanged <path/to/file>track/unhide a file
references: Version Control with Git; Learn Git Branching; How to undo almost anything with git
Last updated
Was this helpful?