====== git ====== ==== Cheatsheet ==== ^ ^ Command ^ ^ Getting started ^^ | Set name and email for commits | ''%%git config --global user.name "John Doe"%%'' \\ ''%%git config --global user.email "johndoe@example.com"%%'' | ^ General ^^ | Only clone with latest revision | ''%%git clone --depth 1 %%'' | | Get new metadata but don't pull | ''git fetch'' | | Check what would be added without adding | ''%%git add --dry-run .%%'' or \\ ''git status -u'' | ^ Diffs ^^ | Show changes (no pager) | ''%%git --no-pager diff%%'' | | Show changed files | ''%%git diff --name-only%%'' | ^ Undo ^^ | Undo and delete all local changes | ''%%git reset --hard%%'' | | Cleanup untracked files | ''git clean -fd'' | | Revert a commit | ''git revert '' | | Revert uncommitted changes | ''%%git checkout -- %%'' | ^ Branching ^^ | Create new branch | ''git checkout -b '' | | Change to branch | ''git checkout '' | | Push to new branch | ''git push -u origin '' | | Merge branch to master | ''git checkout master'' \\ ''git merge '' \\ ''git push'' | | Check which branches exist | ''git show-branch'' | | Delete local branch | ''git branch -d '' | | Delete remote branch | ''%%git push origin --delete %%'' | ^ Mirrors ^^ | Download a mirror clone | ''%%git clone --mirror %%'' | | Change push URL of local repo | ''%%git remote set-url --push origin %%''| | Fetch updates from original | ''git fetch -p origin'' | | Push to mirror | ''%%git push --mirror%%'' | ^ Various ^^ | Specify repository location | ''git -C '' | | Get remote URL of repository | ''git remote get-url'' | | Set new remote URL for repository | ''git remote set-url origin '' | ==== Links ==== * [[https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git|GitHub - How to undo almost anything]]