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?
- How do I delete a Git branch locally and remotely?
- How do I use ‘git reset –hard HEAD’ to revert to a previous commit? [duplicate]
- What is git tag, How to create tags & How to checkout git remote tag(s)
- How do I delete a Git branch locally and remotely?
- How do I rename a local Git branch?
- What does ‘–set-upstream’ do?
- What does ‘–set-upstream’ do?
- Difference between “git add -A” and “git add .”
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- error: src refspec master does not match any
- What does cherry-picking a commit with Git mean?
- How to cherry pick from 1 branch to another
- How to use Git Revert
- How do I undo the most recent local commits in Git?
- How do I revert a Git repository to a previous commit?
- What is the best (and safest) way to merge a Git branch into master?
- How to merge branch to master?
- Git: How do I force “git pull” to overwrite local files?
- What happens when I do git pull origin master in the develop branch?
- Undo a Git merge that hasn’t been pushed yet
- How do I properly force a Git push?
- fatal: Not a git repository (or any of the parent directories): .git [duplicate]
- How can I switch to another branch in git?
- How to remove local (untracked) files from the current Git working tree
- Squash my last X commits together using Git
- Git merge hotfix branch into feature branch
- Git refusing to merge unrelated histories on rebase
- Git submodule update
- How to apply a patch generated with git format-patch?
- What is the `git restore` command and what is the difference between `git restore` and `git reset`?
- What does ‘git merge –abort is equivalent to git reset –merge when MERGE_HEAD is present.’ of Git merge man page mean?
- What does ‘git blame’ do?
- Abort a Git Merge
- What is the difference between git push origin and git push origin master
- GitHub: Permission denied (publickey). fatal: Could not read from remote repository
- Git fetch remote branch
- How to delete a remote tag?
- Updates were rejected because the tip of your current branch is behind its remote counterpart
- Updates were rejected because the tip of your current branch is behind its remote counterpart
- Git: How do I force “git pull” to overwrite local files?
- How to modify existing, unpushed commit messages?
- How do I clone a specific Git branch? [duplicate]
- Git pushing to remote branch
- How to revert a merge commit that’s already pushed to remote branch?
- What is Git pruning?
- Git pushing to remote branch
- git – remote add origin vs remote set-url origin
- How do I undo ‘git add’ before commit?
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- GitHub Error Message – Permission denied (publickey)
- Git fetch remote branch
- How can I see the differences between two branches?
- How to upgrade Git on Windows to the latest version
- Reset local repository branch to be just like remote repository HEAD
- How do I push a new local branch to a remote Git repository and track it too?
- Practical uses of git reset –soft?
- Need to reset git branch to origin version
- How do I push a new local branch to a remote Git repository and track it too?
- Updating a local repository with changes from a GitHub repository
- How do I remove a submodule?
- LF will be replaced by CRLF in git – What is that and is it important? [duplicate]
- git: fatal: Could not read from remote repository
- Git push results in “Authentication Failed”
- What does “Changes not staged for commit” mean
- github changes not staged for commit