SVAN
SVAN

Reputation: 92

git error: The following untracked working tree files would be overwritten by checkout

I just wanted to ask for feedback on what I did and if there was a better way to handle this. I was in the middle of doing a "git pull" when git stopped abruptly due to insufficient permissions.

Some of the new files have been copied from the remote server. However, when I proceed to do another "git pull" it says the following working tree files would be overwritten and to stash or commit the changes. I searched and found a suggest to stash the files, but another permissions error ("unable to unlink files") came up while stashing the files.

This allowed me to complete the git pull, but some of my local changes are now in the stash. When I wanted to run "git stash apply", it gave me the same error about untracked working tree files would be overwritten.

In the end, I had to move the files before I was able to apply the git stash.

Upvotes: 0

Views: 3691

Answers (1)

Zach Olivare
Zach Olivare

Reputation: 4161

You ask if there is a better way to handle your situation, and I believe there is. However, it likely will not completely resolve the permission issues you're experiencing.

I would recommend not using the git pull command at all. What pull really does is a fetch followed by a merge, but you have no control over this process. By first running get fetch --all, you will receive all new commits from all of your remotes. Once these changes have been fetched, you can then manually merge them. This has the advantage of not moving your HEAD pointer (i.e. not changing the files in your file system). Because of that, you should be able to get the changes made by other developers without any OS permission issues.

For me, this process usually looks something like

$ git fetch --all
remote: Counting objects: 250, done.
remote: Compressing objects: 100% (69/69), done.
remote: Total 250 (delta 103), reused 76 (delta 76), pack-reused 88
Receiving objects: 100% (250/250), 64.16 KiB | 0 bytes/s, done.
Resolving deltas: 100% (116/116), completed with 37 local objects.
From github.com:org/repo
   9b49e78..14dc510  master       -> upstream/master

$ git rebase upstream/master mybranch

The rebase in this case is used instead of a merge to apply your changes on top of the latest changes made by other developers that you just fetched. Without the rebase, you would be forced to make an extra commit to merge your changes with the changes made by others. This is the point where the permission issues will likely arise, as rebase is changing where your HEAD points to with each modified commit.

I hope this helps!

Upvotes: 1

Related Questions