Best Practice for cloning repo from github

I’m familiar with how to download a site into Local and then create a Github repo from that local install.

However, now I’ve migrated to a new laptop and I want to clone the repo down - but where to do this? If I try to clone it into a site running Locally it will fail because it needs an empty folder.

Basically how are people cloning repo’s from github and working with them in local?

Hi @simon-wplocal! :wave:

I wonder if this series by Damon Cook might help. It’s a full walk-through of Setting up a Git-based Workflow with Local.

Let me know!

Sam

1 Like

Hi @sambrockway ,

I’d like to take the liberty of commenting on this answer because it’s very close to my problem. The problem I have with this walk-through is that it creates a project directly from localWP, but if I’m working as part of a team and a colleague wants to retrieve a project that has already been created.
Let’s say I have a project created in LocalWP, it’s stored on a github repo with the directory structure APP, CONF (because I want to keep the configuration according to my different projects). My colleague goes into his Local Sites directory and makes a git clone of this project, unfortunately this project does not appear in the list of LocalWP projects. Is there a way of displaying it via a missing file? or a command to execute? or even a call to the apollo API in LocalWP?

Thank you for your answer which would help a lot to implement the LocalWP + WPengine solution in an agency.

Yeah sorry I sort of gave up on this when the github actions turned out to be unreliable in pushing up to production and not renaming all the relevant site URLs (separate issue).
But agree - the tutorial is very much a ‘clean slate’ solution, whereas in real life we’re often coming in at different points in the process.

I’m thinking about creating an addon that will allow you to connect to a github account, get the repos, clone the repo and create the site. Do you think that the hooks and api offered in the LocalWP addons allow you to do this?

Hi @simon-wplocal @cdeclerck :wave:

I’m trying to diagnose the best means to respond because the title “Best Practice for cloning repo from github” is quite personal. I’ve used Local for development across many different-sized agencies, and many projects were set up differently. However, some common patterns evolved. That was what I attempted to cover in my WPE Builders’ Set Up a Local WordPress Development Site’ (4-part) series. However, it does not mean it is the “best practice.” Whatever practice works for you and your team is probably the “best practice” for you and your team.

I’ll attempt to address your insights in sequential order:

I assume you’re seeing this message: fatal: destination path '.' already exists and is not an empty directory. when running git clone [your-GitHub-repo] ., right? So, the Git clone is failing, but Local is not, right?

I’m not clear as to how or why that is a challenge. Unless, you’re assuming a fully automated solution exists, but it does not. Can you delete the auto-generated files and folders within the desired WordPress directory that you’re trying to clone your repo into?

I’m not clear as to what you’re putting under version control vs what you’re ignoring and where you are referencing your install from in this scenario. If you’re putting your Local generated conf/ directory, which includes MySQL, PHP and NGINX configuration files that are required by Local to manage a site then I would advise against it. I believe some of the files contained in Local’s conf/ are dynamically generated and can be modified each time somebody starts and stops a site in Local. This could prove problematic.

Ultimately, I recommend targeting wp-content/ as the root for version control. However, you can also rename Local’s auto-generated app/public directory to something like app/public_backup, clone your GitHub repo anywhere on your local machine, and then create a Symlink. I often do this when setting up a Local site for contributing to WordPress (wordpress-develop GH mirror).

The general Symlink syntax looks like: ln -s /tmp/reference-directory symlink-directory

I would advise against using the Apollo API, because it is not publicly supported, or documented, and subject to change.

Perhaps you could share more details on your desired setup and we can provide clarity to get you there. Even better, if you have a public GitHub repo or Gist of the folder structure you’re going for. Ultimately, when working across a team of developers it is critical to take the time to write simple instructions to onboard them to create a local setup.

2 Likes