#git
git init
: Create a new.git
directory with all repository files.git clone <url>
: Clone an entire repository to the local system to create the working tree.
git status
: Check status of files in working tree.git add
: Track new files / stage modified files.git diff
(git difftool
for graphical): Check changes that have not been staged.git diff --staged
orgit diff --cached
(git difftool --staged
for graphical): Compare staged changes to last commit.git commit
: Commit all staged files.git commit --amend
: Replace previous commit to include minor changes.git rm <file>
: Remove and stage the file's removal. File will be gone after next commit and no longer tracked.git mv <file> <new_file>
: Convenience function for renaming files and staging the renamed file.
git log
: View commit history. Has a wide range of options to narrow down author, date range, output formats, graph mode, etc.
git restore <file>
: Un-modify a modified file.git restore --staged <file>
: Un-stage a staged file.
git remote
: Show list of all remotes.git remote add <name> <URL>
: Add a new remote repository from the URL to your working tree and give it a name.git remote show <remote>
: Show additional information about remote repository.git remote remove <remote>
: Remove remotegit remote rename <remote>
: Rename remotegit fetch <remote>
: Get all data from the remote project not already in working tree. Does not merge automatically.git push <origin> <branch>
: Push any commits to the remote repository.git pull
git tag
: List existing tagsgit tag -a <tagname>
: Create an annotated tag. Other option is to create a lightweight tag. Annotated tags are preferable since they contain additional information--checksum, tagger name, email, date, message, and can be signed with GNU Privacy Guard.git push <remote> <tagname>
orgit push <remote> --tags
: To push tags to the remote. Tags are not pushed automatically.git tag -d <tagname>
: Delete tag in local repository.git push <remote> --delete <tagname>
: Delete tag from remote servergit checkout -b <branchname> <tagname>
: To checkout a tag, first create a branch and then checkout the tag.