Consider the following scenario:
I have the following in my .gitignore
:
files/dependency/config.lua
But since the file used to exist before adding it to gitignore, it was being tracked. I updated my index and removed the file manually following this question. Now, one of my colleague updated this file on remote server.
When I try to checkout to remote branch, it shows:
error: Your local changes to the following files would be overwritten
by checkout:
files/dependency/config.lua
Please, commit your changes or stash them before you can switch branches.
Aborting
So, I read about it; and most of the answers I found tell you to use git stash
. Since I don't have any changes made on local repository, I can not stash them.
I used the --force
option to checkout, but it also returns with an error:
git checkout --force -B myBranch remote/branchname
error: Entry 'files/dependency/config.lua' not uptodate. Cannot merge.
Here, I'd paste my terminal:
┌─[hjpotter92:HEDWIG]─[fooDir]─[06:46 PM] (master u=)
└──$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
┌─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git checkout -b myBranch remote/branchname
error: Your local changes to the following files would be overwritten by checkout:
files/dependency/config.lua
Please, commit your changes or stash them before you can switch branches.
Aborting
┌─[×]─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git stash
No local changes to save
┌─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git checkout -b myBranch remote/branchname
error: Your local changes to the following files would be overwritten by checkout:
files/dependency/config.lua
Please, commit your changes or stash them before you can switch branches.
Aborting
┌─[×]─[hjpotter92:HEDWIG]─[fooDir]─[06:39 PM] (master u=)
└──$ git checkout --force -b myBranch remote/branchname
error: Entry 'files/dependency/config.lua' not uptodate. Cannot merge.
Question:
Is there some way to checkout the remote branch and then either force ignoring the file files/dependency/config.lua
whenever someone pulls in my changes or something similar?