If you want remove all local changes – including files that are untracked by git – from your working copy, simply stash them:
git stash push --include-untracked
If you don’t need them anymore, you now can drop that stash:
git stash drop
If you don’t want to stash changes that you already staged – e.g. with git add
– then add the option --keep-index
. Note however, that this will still prevent merging if those staged changes collide with the ones from upstream.
If you want to overwrite only specific parts of your local changes, there are two possibilities:
- Commit everything you don’t want to overwrite and use the method above for the rest.
- Use
git checkout path/to/file/to/revert
for the changes you wish to overwrite. Make sure that file is not staged viagit reset HEAD path/to/file/to/revert
.
Related Posts:
- How do I ignore an error on ‘git pull’ about my local changes would be overwritten by merge?
- How do I ignore an error on ‘git pull’ about my local changes would be overwritten by merge?
- How to Git stash pop specific stash in 1.8.3?
- How do I force git pull to overwrite everything on every pull?
- git stash apply version
- Why does git say “Pull is not possible because you have unmerged files”?
- Stash only one file out of multiple files that have changed with Git?
- Why does git say “Pull is not possible because you have unmerged files”?
- Stash only one file out of multiple files that have changed with Git?
- How can I git stash a specific file?
- How can I git stash a specific file?
- How do you stash an untracked file?
- How to name and retrieve a stash by name in git?
- How do you stash an untracked file?
- How to name and retrieve a stash by name in git?
- Stash just a single file
- Stash just a single file
- There is no tracking information for the current branch
- Files not updating using ‘git pull’
- git checkout tag, git pull fails in branch
- Why does git say “Pull is not possible because you have unmerged files”?
- How to delete a stash created with git stash create?
- Undo git stash pop that results in merge conflict
- Git diff against a stash
- Move existing, uncommitted work to a new branch in Git
- Is it possible to pull just one file in Git?
- fatal: could not read Username for ‘https://github.com’: No such file or directory
- Git stash pop- needs merge, unable to refresh index
- Git pull – Please move or remove them before you can merge
- How to recover stashed uncommitted changes
- How to `git pull` while ignoring local changes?
- Difference between git stash pop and git stash apply
- Git push requires username and password
- How do I check out a remote Git branch?
- What does ‘–set-upstream’ do?
- What does ‘–set-upstream’ do?
- How to use Git Revert
- How do I properly force a Git push?
- How to remove local (untracked) files from the current Git working tree
- Git merge hotfix branch into feature branch
- How to modify existing, unpushed commit messages?
- Git pushing to remote branch
- How to revert a merge commit that’s already pushed to remote branch?
- GitHub Error Message – Permission denied (publickey)
- How do I push a new local branch to a remote Git repository and track it too?
- How do you push a tag to a remote repository using Git?
- Gitignore not working
- How to solve SSL certificate: self signed certificate when cloning repo from github?
- How do I revert a Git repository to a previous commit?
- How do I resolve git saying “Commit your changes or stash them before you can merge”?
- How to revert multiple git commits?
- How do I rename both a Git local and remote branch name?
- How do I fix a Git detached head?
- How to cherry-pick multiple commits
- Another git process seems to be running in this repository
- rejected master -> master (non-fast-forward)
- merge one local branch into another local branch
- How to get the current branch name in Git?
- Git error on commit after merge – fatal: cannot do a partial commit during a merge
- Can I share my private GitHub repository by link?
- How to rename a directory/folder on GitHub website?
- Download a single folder or directory from a GitHub repo
- Is there a “git touch” so I can push the same file with a new timestamp?
- Branch from a previous commit using Git
- Throw away local commits in Git
- Hard reset of a single file
- Hard reset of a single file
- How to remove remote origin from a Git repository
- Not a valid object name: ‘master’
- .gitignore and “The following untracked working tree files would be overwritten by checkout”
- git add remote branch
- Undo a git stash
- Set up git to pull and push all branches
- Unity Collaborate vs GitHub
- SourceTree keeps asking for Github password
- Git’s local repository and remote repository — confusing concepts
- How to change the license for a project at Github?
- Git add all files modified, deleted, and untracked?
- How to switch back to ‘master’ with git?
- Github Authentication Failed – … GitHub does not provide shell access
- How do I pull files from remote without overwriting local files?
- How can I see which Git branches are tracking which remote / upstream branch?
- How to keep a branch synchronized/updated with master?
- Your repository has no remotes configured to push to
- Uninitialize git repository
- Specify an SSH key for git push for a given domain
- How do I “un-revert” a reverted Git commit?
- How to create a local branch from an existing remote branch?
- git push not send changes to remote git repository
- How to merge a specific commit in Git
- What is the .git folder?
- How to use Git and Dropbox together?
- Git: Where exactly is the “working directory”?
- What exactly does the “u” do? “git push -u origin master” vs “git push origin master”
- What is the usual process of saving changes made at the CMS level into source control?
- Add latest commit info on login footer using login_footer hook
- WordPress Core files not being ignored by Git
- Display GitLab repositories of the logged in user on a page
- How to tell which local branch is tracking which remote branch in Git?
- How to retrieve the last modification date of all files in a Git repository