Start a repository in this directory
Changegit init
Use this for a project that is not already a Git repository.
COMMANDS
From your first repository to branches, remotes, and undoing a change.
68 commands
git init
Use this for a project that is not already a Git repository.
git clone REPOSITORY_URL
Creates a new project directory. Use this instead of git init when the project already has a remote repository.
cd PROJECT_DIRECTORY
After cloning, enter the directory that Git created.
git config user.name "YOUR NAME"
Run inside the repository.
git config user.email "YOU@example.com"
This email is recorded in new commits.
git status
Shows the branch, staged files, unstaged changes, and untracked files.
git diff
Shows changes to tracked files; new untracked files are not included.
git add -- FILE
Add the file content you want in the next commit.
git diff --staged
Check exactly what the next commit will contain.
git commit -m "Describe the change"
Saves the staged changes in repository history.
git status --short
git branch
git switch -c BRANCH
Creates a new local branch.
git switch BRANCH
Uncommitted changes can prevent switching.
git merge BRANCH
Switch to the receiving branch first. Conflicts may need resolution.
git remote -v
git remote add origin REPOSITORY_URL
For a repository created with git init. Cloning normally adds origin for you.
git branch --show-current
Use this name in place of BRANCH when pushing.
git push -u origin BRANCH
Uploads commits and sets the upstream. Review the destination and content first.
git fetch origin
Updates remote-tracking references without merging into your branch.
git branch --all
git pull --ff-only
Requires an upstream. Refuses an update that would need a merge commit.
git push
Uses the configured upstream.
git log --oneline --graph -15
git show --stat HEAD
git blame -- FILE
git restore --staged -- FILE
Keeps the working file. Requires an existing commit to restore from.
git restore -- FILE
Replaces tracked working content with the staged version. Uncommitted edits can be lost.
git revert COMMIT
Creates an inverse commit; conflicts may need resolution.
git reflog -15
Useful for finding commits after a mistaken branch move.
git stash push -u -m "Pause current work"
Ignored files are not included. Review the files before stashing.
git stash list
git stash show -p stash@{0}git stash apply stash@{0}May conflict with current edits.
git stash pop
Conflicts can leave the stash available.
git stash drop stash@{0}Deletes this saved entry. Confirm you no longer need it.
git add -p -- FILE
Read each hunk and choose y or n.
git commit --amend --no-edit
Stages must already contain the intended correction. Replaces the commit.
git reset --soft HEAD~1
Moves the branch back; use on your own unpublished history.
git rebase BASE_BRANCH
Replays commits and can stop at conflicts.
git rebase -i HEAD~3
Edit the todo list for three local commits; commit IDs change.
git rebase --onto NEW_BASE OLD_BASE BRANCH
Replays BRANCH commits after OLD_BASE onto NEW_BASE.
git commit --fixup=COMMIT
Stage the correction first. Pair with autosquash.
GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash BASE
Bash example. BASE is excluded from the replay; use the parent of the earliest target.
git rebase --continue
Stage resolved files first.
git rebase --abort
Returns to the state from before this rebase.
git cherry-pick COMMIT
Can conflict; copies the change with a new commit ID.
git merge --squash BRANCH
Does not create a commit or merge parent; review and commit afterward.
git reflog --date=iso
Local reflogs are not permanent backups.
git branch recovered COMMIT
Creates a reference without replacing your current branch.
git log -S "STRING" --oneline -- FILE
git log -G "REGEX" -p -- FILE
git bisect start BAD_COMMIT GOOD_COMMIT
Temporarily checks out candidate revisions.
git bisect run sh ./check.sh
The checker returns 0 for good, 1–127 except 125 for bad, and 125 to skip.
git bisect reset
Returns to the branch or revision from before bisect.
git grep -n "PATTERN"
git blame -L 10,25 -- FILE
git mv -- OLD_NAME NEW_NAME
For a case-only rename on Windows, use an intermediate name.
git rm --cached -- FILE
Commit the removal and use an appropriate ignore rule.
git update-index --chmod=+x -- SCRIPT
Changes the Git index even when filesystem mode support differs.
git ls-files --stage
git tag -a TAG -m "Release description"
Creates a local tag; it is not automatically pushed.
git show TAG
git worktree add ../WORKTREE BRANCH
The branch must be available for checkout.
git worktree list
git diff > change.patch
Untracked files are not included.
git apply --check change.patch
git apply change.patch
Changes working files; does not commit them.
No match. Try another command, task, or turn off the changes filter.