Rob N
Rob N

Reputation: 1

Setting up Git for existing drupal directory

I need help working out how to setup a git (bitbucket) repository in an existing Drupal html folder. I should point out I'm also new to coding, Drupal and Git. I've fallen into this role and I'm well over my head.

We use Drupal features to manage the configuration of the site and it's these changes which are pushed to the bitbucket repository. The Drupal folder has lots of additional files which aren't part of the repository as they are images, downloads etc... and won't ever be part of the bitbucket repository.

So I need to work out the following (I've managed to work out bits myself):

It seems straight forward but I keep running into errors

Git Init Sets up the folder

git remote add -t dev origin <bitbucket repository> Connects to the remote repository branch dev

I then try a git pull, but get an error because files already exist in the local folder.

I want to overwrite the local files which are part of the bitbucket repo but I also want to keep the files which aren't part of the bitbucket repository.

I've tried applying suggestions I've seen from other situations and I'm now in a bit of a mess with a detached head file etc... Which I'll fix separately.

If a suggested workflow could be made that would be great.

Error Message as requested

git pull <repository> <branch>
  ...
    themes/seven/reset.css
    themes/seven/screenshot.png
    themes/seven/seven.info
    themes/seven/style-rtl.css
    themes/seven/style.css
    themes/seven/template.php
    themes/seven/vertical-tabs-rtl.css
    themes/seven/vertical-tabs.css
    themes/stark/README.txt
    themes/stark/layout.css
    themes/stark/logo.png
    themes/stark/screenshot.png
    themes/stark/stark.info
    update.php
    web.config
    xmlrpc.php
Please move or remove them before you can merge.
Aborting

Upvotes: 0

Views: 112

Answers (1)

Pockets
Pockets

Reputation: 1264

I strongly advise reading chapters 1-3 of Pro Git, which will help you learn the Git model, which is hands-down the most important thing here.

That being said, it sounds like you're in a weird situation:

  • You have an existing repository which tracks Drupal configuration on Bitbucket.
  • You have a directory on a server which contains a Drupal configuration that
    1. is not set up with version control, and
    2. also contains multiple assets (e.g. images, downloads) which version control should not track.
  • You want to bring the directory under version control.

Here's the problem: because the directory is not currently being version controlled, it is not easily reconciled with the version controlled copy on Bitbucket. Moreover, when you run git init, that creates a new repository, with a completely separate and independent history. You can technically merge the two together in a brute-force fashion, but that is less than ideal.

Keep in mind that the solution I am about to suggest is not necessarily recommended, and that it also assumes the current Drupal config on the server is derived from dev on the Bitbucket repo.


What you need to do is manually craft a new repository - one whose history corresponds to the Bitbucket repo but whose working tree is your current directory. In the root of the configuration directory, do this (this assumes foo/ does not previously exist):

rm -rf .git/
git clone --no-checkout <bitbucket_repo> foo/
mv foo/.git/ .
rm -rf foo/

and this should, in theory, leave you in a position to integrate your existing config dir with the Bitbucket repo. Of course, I'm not 100% sure if this is what you were aiming to do, but it does sound like it.

Upvotes: 2

Related Questions