Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spawn-guy/6a87fefbff0b85669e1e48194b163b63 to your computer and use it in GitHub Desktop.
Save spawn-guy/6a87fefbff0b85669e1e48194b163b63 to your computer and use it in GitHub Desktop.

Reset

You can reset the commit for a local branches using git reset

To change the commit of a local branch:

git fetch

git reset --hard "@{upstream}"

On Windows or with PowerShell, specify "@{u}" (with double quotes).

git fetch

git reset --hard @{upstream}

The advantage of specifying @{u} or its verbose form @{upstream} is that the name of the remote repo and branch don't have to be explicitly specified.

Be careful though, as the docs put it:

Resets the index and working tree. Any changes to tracked files in the working tree since are discarded. If you want to actually keep whatever changes you've got locally - do a --soft reset instead. which will update the commit history for the branch, but not change any files in the working directory (and you can then commit them).

Clean

Erasing your project directory and re-cloning from the remote, to remove even files that are in your .gitignore, use git clean to remove untracked files, optionally also with -x:

git clean -df

Warning: git clean -xdf is irreversible and you may lose files and data (e.g. things you have ignored using .gitignore).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment