Start with same folders and different files

Asked

Viewed 76 times

1

I have a project that I kept only copying files to the server via SSH. Some of these files were edited manually directly on the production server. Now I’m starting Git versioning in Bitbucket, and I’ve already accomplished a push initial files that are on my development machine.

How to do it now to merge what’s on the production server and what’s already in Git, knowing that the production server has some files modified directly there, and that it doesn’t contain these modifications in the Git repository or on my development machine?

I remember that I haven’t done any action regarding Git on the production server yet. I’m in doubt about how to proceed from now on.

1 answer

0


Do the following.

Suppose your project on the server is in the folder /var/www/projeto. Clone your repository into another folder, for example, /var/www/projeto_git:

git clone <repositório> <pasta de destino>

The branch that will be cloned will be the standard master. Create another branch called, for example, servidor:

git checkout -b servidor

Then copy all files from your project folder to your repository:

cp -R /var/www/projeto /var/www/projeto_git

This done, Embed the files with a very clear message (e.g., "server files") and send them to the remote server:

git add --all
git commit -m <mensagem de commit>
git push -u origin servidor

That way you’ll have two branches in its repository: the master, which contains the original design, and servidor, that has its project modified with the files of the server on which it is hosted.

(Just one detail: Since you don’t have much experience with Git, be careful when viewing files with sensitive information in a public repository; prefer private repositories.)

Finally, if you want to download the modified project in your development environment, run the following command:

git checkout -b servidor origin/servidor

In this way, it is possible to compare the two branches (that is, which files exist in a branch and not on the other) and the differences between files with the command:

git diff master..servidor
  • Thank you very much Rodrigo. I am now testing this solution and that’s right. I appreciate your willingness to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.