My Favorite Git Commands
Git and GitHub are pretty much a part of a developer’s work day, and each developer tends to define their set of tried and true Git commands. Here is my list of Git commands (in no special order):
git init: initialize a repositorygit branch -a: see all branches, including active branchesgit status: see the status of the active branch (and read hints for the next steps or fixing errors)git checkout <BRANCH> | <COMMIMT_ID>: activates branch or detaches head to commit in the current branchgit show <COMMIT_ID>: show commit information (or add the--statoption for a short summary)git diff --name-only <BRANCH_X>..<BRANCH_Y>: see the difference between branch X and branch Ygit commit -am "Commit message here": commit working tree by adding and message all in onegit merge <BRANCH>: merge the branch into the current working treegit log --oneline --all: see the short commit history of all branchesgit diff-tree --no-commit-id --name-only -r <COMMIT_ID>: see files from the commitgit reset --mixed <COMMIT_ID>: reset repository to commit, but keep indexed and untracked changesgit reset --hard <COMMIT_ID>: reset repository to commit wiping out all working tree changesgit remote --verbose: show remote repositorygit rm --cached <file_name>: remove the specified file from Git tracking-
git clean -f | -df: remove untracked files or untracked directories -
git branch -d -r <REMOTE>/<BRANCH>: remove the upstream branch in a local clone git remote prune <REMOTE>: removes references to remote branches that no longer existgit push -u <REMOTE> <BRANCH>: push the local branch to the remote
Well, there you have it. I’ll be adding/editing as necessary.