Resources
  • Introduction
  • ASP.NET
    • F#
    • C#
    • .NET Core
    • MSBuild
    • Tools
  • (T-)SQL
    • Snippets
  • Typescript
  • Javascript
    • Angular
    • React - Redux
    • Stats
  • Progressive Web Apps
  • Design and UX
    • HTML
    • CSS - Cascading Style Sheets
  • Computer Science
    • Architecture and Patterns
    • Database
  • Security
  • Testing
  • Hacking and Tinkering
  • Tools
  • CLI Cheat Sheets
    • Git
    • Dotnet core
    • Docker for Windows
    • Powershell
  • Progressive Web Apps
  • Miscellaneous
Powered by GitBook
On this page

Was this helpful?

  1. CLI Cheat Sheets

Git

PreviousCLI Cheat SheetsNextDotnet core

Last updated 5 years ago

Was this helpful?

Clear all unstaged changes, including ignored files:

> git clean -dfx

Find removed file:

> git log --all --full-history -- **/thefile.*

Git pull and rebase:

> git pull --rebase

# Once
> git pull --rebase --autostash
# Permanent
> git config pull.rebase true
> git config rebase.autoStash true

> git commit -m "Something terribly misguided"              (1)
> git reset HEAD~                                           (2)
<< edit files as necessary >>                               (3)
> git add ...                                               (4)
> git commit -c ORIG_HEAD                                   (5)
> git rev-list -n 1 HEAD -- <file_path>                     (1)
> git checkout <deleting_commit>^ -- <file_path>            (2)
> git branch --merged | ? {$_[0] -ne '*'} | % {$_.trim()} | % {git branch -d $_}
> git fetch --prune
> bash
$ git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D

Staging Patches:

> git add -i # Choose option "5" or "p" as in "patch"

Undo Patches:

> git checkout -p <optional filename(s)>

Replace remote with local branch:

> git checkout BranchToPushTo
> git reset --hard BranchToReplaceWith
> git push --force
# WARNING! Only do this in your own branches!
> git rebase --interactive 'bbc643cd^'
# NOTE! Modify 'pick' to 'edit' in the line mentioning 'bbc643cd'
> git commit --all --amend --no-edit
> git rebase --continue

Oh shit, git!
Config Git to do a stash before pull and rebase automatically:
Undo latest unpushed commit:
Find and restore a deleted file:
Remove all local branches that have been merged into the branch currently checked out:
Remove untracked branches (replace -D with -d to only remove fully merged branches:
Modify a specific commit: