André Amorim

Crafting Web Experiences


//

Clean a Git project as it’s newly cloned

You might need this mostly if you are unable to pull since the project is not clean. In short, you can use “git reset –hard” to get back to the last commit. But, you can loose the changes you recently made.

Before doing this, I recommend stashing your changes first.

1. Optionally, to get latest info from remote server:

git fetch

2. Get to the final commit on master:

git reset --hard origin/master

or to any specific commit:

git reset --hard <commit_id>

or to another branch:

git reset --hard origin/<branch_name>

3. Cleanup the untracked files:

git clean -df

or cleanup all the other files including the ignored ones:

git clean -df

Published date:

Modified date: