Panagiotis Koursaris Panagiotis Koursaris - 2 months ago 5x
Git Question

Git initialize old project from local pc to remote server

I've an old project in the production. The code of this project is in my local pc without the images that uploaded in the server. Today I've extended the project with new features.

Now I want to use git with this project. I've initialize git in it. Then I have created a repository to my bitbucket account and I have pushed my project from my local pc.

The problem that I have is that I want to

the project from bitbucket to my server keeping the images that there aren't in the bitbucket. How can I do that?

Could I copy only the .git file from local to my server and then I
the project from bitbucket?


As always before trying something out: do a backup beforehand

In case the folder public/img/ does not exist in the repository (is not tracked) the case is quite easy.

  • On your server go to the folder which should be the root of the repository
  • Initialize an empty git repository in this folder

    $ git init
    Initialized empty Git repository in /some-directory/
  • Add your bitbucket repository as a remote

    $ git remote add origin <url-to-bitbucket-git-repo>
  • Fetch all your fresh changes

    $ git fetch origin
  • Finally check out the branch you want (assuming master) and set up tracking

    $ git checkout --track origin/master
  • It will not overwrite your public/img/ folder if it does not exist in the repository

Handling old application files

Create a new branch to hold the old files

git checkout -b <old-application>
git add -v old-application-files/
git commit # Message should indicate that this is an older state of the application

Make sure not include the images folder into this commit (these commits)

Now the git checkout master should work and you can see what was changes between the old state and the current one by doing a git diff

git diff <old-application> master

In the future simply go to this folder and do a git pull