git deployment: untracked working tree files overwritten by merge

I’m trying to implement a git based deploy procedure like in to deploy a web application.
Basically it consists of two repos on the live server:

  • a bare repo, in which you push, the “hub”
  • a normal repo in the web server public directory, in which you pull from the “hub”. This is performed automatically if the hub has an
    appropriate post-update hook.

The problem is that in my projects I have many directories, like /upload/, which contain sample data during development and real live data on the webserver.

  • Deploying my Rails app via Git on an Ubuntu 14.04
  • Best way to deploy git projects (with submodules) to FTP server
  • How do I run gulp.js in my core project when deploying to Azure using git?
  • Deploying with git
  • Where to store private keys for a continuous integration (CI) deployment?
  • Deploying with Git/Github
  • Ideally I would like to keep the upload/ folder on local repo, but not pulling it on the live repo.
    Now, “partial” pull it doesn’t seem possible, isnt’it?

    So, even if not an optimal solution (I can’t clone sample data in local repos), I’m trying to ignore those folder, but:

    • I added the upload/ folder to .gitignore on local and live repos.
    • I removed it with git rm –cached upload/
    • I pushed the project to the bare “hub” repo
    • in the live repo I pull from the hub
    • I get the error: untracked working tree files would be overwritten by merge…upload/xxx

    It seems to me that the upload/ folder is still somewhere…
    Indeed, while writing this, I see that cloning from the hub, the folder upload/ is cloned too!

    The only solution would be then, to remove completely the folder from all the project history, like I’ve seen in several questions?

    Is this going to force all the others colleagues working on different branches to some messy rebase?

    It’s probably difficult to explain all this and to grasp it, but any idea is welcome.

  • git clone ends with Broken Pipe
  • Sub folder in Git project?
  • How do I squash commits on a branch that has children
  • Very strange git behavior when merging old branch into develop
  • Git is not ignoring tmp files
  • Git fetch and merge skipped asking me for conflicts
  • 2 Solutions collect form web for “git deployment: untracked working tree files overwritten by merge”

    You don’t need to do all that, assuming you wouldn’t want to checkout an older commit than the head of your branches.

    What you need to do is to eliminate upload/* in a new commit, and from then on, anyone seeing the new commits wouldn’t see the upload directory.

    Obviously, you would want to back the upload/* files up on the “hub” and on any clone who would pull from it, remove upload in a commit, and then put the backup back in its place. Now the data exist in your directories, but git wouldn’t be tracking them anymore.

    Note: if you don’t backup, you would be deleting the upload/* data on hub (recoverable by checking out an older commit) or anyone pulling from it (error by git if they are not tracked, or recoverable by checking out an older commit if tracked). Nevertheless, better just back it up first.


    $ git init
    $ mkdir upload
    $ echo 'upload/*' > .gitignore
    $ touch to_track upload/not_track
    $ git add .gitignore to_track upload/not_track
    $ git commit

    Now you have upload/not_track in the repository.

    $ cp upload/not_track ../backup
    $ git rm upload/not_track
    $ git commit
    $ mv ../backup/not_track upload/

    Now the files in the current directory haven’t changed, but upload/not_track is not in the repository any more (from this commit forward).

    Difficult to be sure without seeing the git repo, but what you’re describing should not be happening.

    Have you checked the folder for hidden files (for example, a .gitignore file in there, or .DS_Store (Mac folder browser cache) or similar?). Ignored files are not removed automatically by git rm.

    If you git ignored before you git rm you’ll have to either remove it from ignore, or straight rm it.

    Git Baby is a git and github fan, let's start git clone.