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 fetchCode language: Bash (bash)

2. Get to the final commit on master:

git reset --hard origin/masterCode language: Bash (bash)

or to any specific commit:

git reset --hard <commit_id>Code language: Bash (bash)

or to another branch:

git reset --hard origin/<branch_name>Code language: Bash (bash)

3. Cleanup the untracked files:

git clean -dfCode language: Bash (bash)

or cleanup all the other files including the ignored ones:

git clean -dfCode language: Bash (bash)






Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.