Skip to content

Latest commit

 

History

History
144 lines (90 loc) · 4.95 KB

File metadata and controls

144 lines (90 loc) · 4.95 KB

git

Full command reference.

Commands

git add options <pathspec>

Stage files mathing <pathspec> for commit. <pathspec> * adds all in repo.

  • -n dry-run, show files that would be added/ignored.
  • -p Interactively stage parts (hunks) of files.

Manage branches.

Without options it lists the branches.

  • -d <name> delete branch <name>.
  • <name> create a branch <name>.

Switch branches or restore working tree files.

  • <branch> switch working tree to <branch>.
  • -b <branch> create a branch named <branch> and switch to it.

git clone <URL>

Clone a repository into a new directory.

Commit changes from the staging area. Without options the default editor opens to enter the commit message.

  • -m "<msg>" include the commit message <msg> on the command line. The editor will not be used.
  • --amend change the latest commit to include extra file changes or change the commit message. Do not use this when the commit is already pushed to a shared repository.

git config --global core.editor <cmd>

Set editor, for things like commit messages, to <cmd>, for example

"'C:\Program Files (x86)\Notepad++\notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Note the single plus double quotes are needed on Windows or git cannot open the program. The additionl options are specific for Notepad++ to create a basic new instance without other tabs. Found here.

Shows differences between all changed files in working tree and HEAD.

  • <file> shows only the differences of <file>.
  • --cached shows the differences that are staged for the next commit.

Creates an initial Git repository from the current directory. It creates the .git directory. The common next step is to create a .gitignore file.

Show commit logs

  • --name-only: include names of changed files in output.
  • --oneline: shows commit hash and first line of the message (alias for git log --pretty=oneline --abbrev-commit).
  • -- <path>: show log of <path>.
  • <tag-1>..<tag-2>: log commits between <tag-1> and <tag-2>.

git merge --no-commit --no-ff <branch>

Do a test run of a merge without committing changes. Files are changed after this command, to reset everything to the state before the merge use git merge --abort.

Send changes from the local repo to the remote repo.

Tags are not included by default. To push a single tag use git push origin <tagname>. To push all tags that are not present in the remote repo use git push origin --tags.

  • -u origin <branch> add branch <branch> that exists locally but not remote, to the remote repo, like GitHub.

git remote <command>

From git manual: Manage the set of repositories ("remotes") whose branches you track.

  • prune <name> [--dry-run] delete references to local branches that no longer exist on the remote repo <name> Normally, the <name> origin refers to the repo on GitHub. --dry-run lists what would be deleted, without doing it. Branches itself are not deleted.

git reset <commit> --hard

Resets the current HEAD to the specified state.

Do not use this when the commit is already pushed to a shared repository.

Undo the commit and change the files back the state before the commit. use it on the last commit.

If the commit has been pushed, create a new commit to change the files back to their origina state.

Restore the version of <file>. If <file> is changed but not staged, restores to the version before the changes.

git revert HEAD | <commit>

Revert the changes that were made by a commit.

  • HEAD revert the latest commit to the HEAD.
  • <commit> the specific commit to revert.

Show commits including file changes.

Show untracked files and changed files that are not staged.

Show and manage tags. See git push for information about pushing tags to a remote repo.

  • -a <version> create an annoted tag for <version>.
  • -m the message for the tag. If omitted the configured editor opens to enter the message.