Steps for Cloning Repo to HostGator File Manager (gotchas included!)
Coming from a graphic design background, Git has always been a bit challenging for me. I often long for a visual UI and a simple way to do the tasks without using Terminal, but in the end, I slowly work my way through step-by-step commands in Terminal.
Today, I needed to clone a static website that I added to my BitBucket repo to a shared hosting plan on HostGator. It was more challenging than I expected. If you’re running into errors, or are looking to do the same thing, I hope this write-up helps you.
1. Create SSH Keys
Although cPanel has a SSH key generator, the keys generated will not work because they have required passcodes. You are not able to Generate Key’s with the “Key Password” field blank because of form validation rules. This is gotcha number one.
Instead, you will need to generate keys manually from cPanel’s Terminal. When you generate the key manually you can leave the password blank.
Will I have to use Terminal to make my HostGator SSH keys?
The answer is yes. If you are in HostGator’s cPanel, you can not use the SSH Access tool for SSH Key generation because it forces the inclusion of a password.
In cPanel terminal, which is automatically logged in for you.
Use the command:
ssh-keygen -t rsa -C YourEmailAddress
To leave a blank passphrase, click return or enter on your keyboard.
2. File Manager Preparation
The next gotcha is: the folder into which you’re cloning your project must be empty. If it is not empty, you’ll get an error message such as “Error: You cannot use the “/” directory because it already contains files.”
Empty includes hidden files (files that start with a period.)
3. Cpanel Git™ Version Control
What cloning address do I use from BitBucket?
I did not have success using the BitBucket clone this repo HTTPs address, even though the cPanel instructions seem to say that the clone URL could work with the HTTPS protocol. I could not get https://yourusername@bitbucket.org/yourusename/production.git to work.
However, I did have success using the BitBucket clone this repo SSH address.
So, in cPanel’s Git Version Control field for Clone URL, I used git@bitbucket.org:yourusername/production.git successfully.
4. Paste Access Key into BitBucket
There is another possible gotcha in this step. In BitBucket you can add keys at the account level or repository level AND the same key can not be added to both. In this scenario, the key should be added to the repository.
In BitBucket, click to your repository and then branch you want to clone. Next go to Repository Settings > Security > Access Keys.
You’ll paste in your key that you generated from cPanel. You can copy the key from the SSH Access tool (even if you created the key in Terminal) or in Terminal use the command cat ~/.ssh/id_rsa.pub
to reveal your code. You can then manually copy and paste it. pbcopy
does not work.
References
I hope this helped you. If you’re looking for additional resources, I found this StackOverflow post very helpful in sorting out my errors; Many of the instructions and notes included in this blog post were garnered from the StackOverflow forum post.