Interesting GitHub question

I have most of my private repositories hosted on They provide free space for private repos. GitHub requires a paid plan to host private repos. I have lots of private repos. However, it seems that everyone wants to see coding samples. GitHub no longer requires a paid plan to host public (open source) repositories, so why not take a fresh look?

I don’t want to show off all my mistakes in the public GitHub account, so I’m keeping the private BitBucket account. How do I push additional BitBucket snapshots that are sort-of cleaned up to the public GitHub account?

Step 1: Set up a public GitHub repository
That’s easy. I already have a GitHub account that I used when I was taken the Berkeley Coursera class. The account was private while I was taking the class, but became public when the class ended. Setting up a new repo in GitHub is easy and they provide help pages if you have questions.

Step 2: Figure out how to push the local repos
I already use GitHub Desktop (for Mac) to clone tutorials. In the end, I decided not to use it to clone and push the BitBucket repos to GitHub because I was concerned the alias to BitBucket would be overwritten.

Step 2a: Use the command line interface to create another alias
GitHub (and BitBucket) will automatically create a remote alias when creating a remote repository and use it to push snapshots up to that repository. I’m already using that alias (origin) and was concerned that GitHub Desktop would overwrite the alias to github if I reset it using GitHub Desktop. However, I can use the CLI to create a new alias.

> git remote add github

When I check the aliases using “git remote -v”, I see another set of aliases pointing to a different server.

So, while I’m stuck with dead end and intermediate steps, commits go to BitBucket. Once I figure everything out and arrive at a good stopping point, the commits all get pushed as a block to GitHub.

> git push github master

I can live with it. Even better, I noticed in SourceTree (Atlassian/BitBucket’s Mac desktop app) that the new alias appears in the remotes list. Potentially, I could update SourceTree settings to go back and forth between both repositories. Interesting.

Cleaning up Mercurial & Git repos

Recently, I cloned a repo that I created on my laptop and pushed to Bitbucket back down to my desktop. At that point, I discovered that I had included all the vendor files for the project within the repository. That’s a no-no. It’s a waste of space, mainly because the dependent libraries can be downloaded by running composer once the new clone is created. So, I decided to remove the vendor files from the repository without dropping them from the file directory.

I thought I had solved the problem by updating Mercurial’s .hgignore file, which is used by Mercurial to mark which files and folders to not track. Unfortunately, the vendor files had been included in the initial repository creation. Going forward, .hgignore would ignore new files and folders in the vendor directory, but I still needed to forget the files already listed. It turns out that ‘hg forget file_name’ would do the trick.

I wanted to be sure it worked, so I created a ‘tests’ folder and touched a file inside that folder. Sure enough, the file appeared in Mercurial’s commit list. I ran a commit, then tried

> hg forget a.php

This removed the file from the committed list, but the file still appeared in the staging area, which did not make sense. When I updated .hgignore to not track the ‘tests’ directory, the new file disappeared from the staging area. That’s what I wanted.

I now had all the files in the vendor directory for forget. I moved to the vendor directory and entered the following command to forget the .json files:

> hg forget -I **.json .

That removed the .json files from the commit list. I did the same for .js, .map, .txt, .conf, .tpl, .yml, .css and .html files. Oddly, only one .php file was forgotten in this manner in the vendor directory. I wonder what might happen if I try ‘ > hg forget -I vendor/** .’ ? (I may try that if I have to clone this repo again.)


It takes less command line work to forget files in git. This command did it all:

> git rm -r –cached vendor

where rm (folder remove) -r (recursively) –cached (from index only) vendor (the folder name). That’s much easier.

Still valid!

I knew I had written about using Mercurial and Git at the same time. I realized this would be useful when I decided to rebuild a helper application and (eventually) post it to Heroku. Heroku uses git to push files back and forth. As mentioned before, I used Mercurial first and was used to it. I want to stick with it because I’m used to to SourceTree, their desktop client. I followed my old instructions and it worked.

I noticed that Github allows unlimited private repositories. That was one of the reasons why I initially chose Bitbucket over Github so many years ago. I still have to pay $7/month, which I don’t have to do with Bitbucket. Ideally, the school would pay for it, but that’s not happening for a while.

(future me here)

I know why I did not drop Bitbucket entirely. It’s the free private repositories that I like. What I should have done is created the repo as a Git repo and saved that up to Bitbucket. I was not thinking.

reloading files … not fun

My workstation has a weird short circuit somewhere that has to be tracked down at the help desk. While I wait, I’ve tried to install my work on the department laptop. It has not been easy.

Luckily I pushed copies of what I was working into repositories for off-site storage. Unfortunately, those repositories were slightly out of date. I did not lose anything from the database archives, from what I can tell. The CakePHP 3 repo is about two weeks out of date. I convinced myself it was OK, since I spent two weeks trying to solve a dead end regarding JQuery, AJAX and calls back to the original CakePHP action. It should be easy, but I have not been able to track down the answer yet.

I cloned the archive repository locally and reloaded that SQL into the local copy of MySQL. That went fine, with some minor issues. You can’t load a table with foreign keys until after those related tables are loaded first. (Of course.) If the file is too big to load through phpMyAdmin’s 2 MB file limit, zip it and try again. (That answer was staring at me all day long. Very annoying, once I found it.) Everything looks fine, so I move on to the next action.

Next, I needed to reload the CakePHP repository. Installing CakePHP is a little more involved than cloning a repository. For starters, the docs say I need Composer to install, which is not loaded on the laptop. I’m not sure why that would be needed for a repository clone, but why not? It can’t hurt, and I might need it, so I load Composer using homebrew. I found my old instructions for installing composer, but I forgot the final instruction, about ignore dependencies. I’m sure I thought it was obvious at the time, but it’s better if I remember putting it in. Finally, Composer is loaded, updated and ready to go.

Next, I remember that CakePHP needs specific PHP extensions to run properly (mbstring, openssl, and intl). The one I did not have was the intl extension. I checked my notes again and found a very good description of how to install the intl extension. That’s done, finally. I’m ready for CakePHP.

I clone the CakePHP repository. When I try to load it, it bombs. I get an error about permissions denied in the logs folder. I remember this error from another installation, so I’m confident I can track down the issue. I also notice that the vendors directory is empty. Now that I have the composer.json file, I update Composer and run it again. The vendors directory is back, but I still have the permissions problem.

While checking the vendors directory, I went to the config directory for some reason. I noticed that my config/app.php file is missing. That’s odd. The app.php file controls database access, so I’m surprised to see it’s missing. I finally get access to the Time Machine drive of the old machine and copy the latest version of that app.php file over. The permissions problem is not solved, so I decide to start from the basic installation with a test site described on the CakePHP web pages.

I stumble around, comparing user/group settings on folders between the fresh install and the Time Machine backup. Eventually, I get them set to something that looks like it works. However, the links to the CakePHP css pages are not working. I remember this again from a previous install. This has to do with apache and how it blocks access to .htaccess files (or something like that.)

I track down the section in the CakePHP documentation regarding URL rewriting, so I figure out how to set apache properly to get it to read CakePHP’s .htaccess file. While there, I find a related link that tells me exactly how to fix the logs and tmp directory. I’m almost ready, except for the part where my archives have disappeared. Somehow, they tables I loaded disappeared at some point. Very strange. This is important since I built a small website that uses CakePHP to display the data in the archive tables. Next stop. What happened to the archive tables?

hg vs git? Why not both?

For my projects, I prefer Mercurial over Git as the DVCS. Mostly, it’s a personal preference. Four years ago, when I was investigating what to use instead of Subversion, Mercurial seemed easier, so I stuck with it. Bitbucket, which at one time only hosted Mercurial repos, is free for personal projects, while Github charges at least $7/month to hold projects. SourceTree (Atlassian’s desktop app for DVCS) first handled Mercurial repos, then eventually handled Git repos. These people feel that git is good for distributed projects, while Mercurial is good for personal repositories.

SourceTree makes Git really easy to use. Eventually, I’ll get used to the command line instructions for git. I do know that more and more projects are saved in github and provide git instructions to download the files. I’ve used Heroku for a class on web applications and it made deployment very simple, as long as the project was stored it a Git repo. So … for now, I’ll run them both.

Usually, I start personal projects in Mercurial and get it set up and backed up to Bitbucket using SourceTree. I’ve realized that I need to set SourceTree/Mercurial to ignore the git files needed. Before setting up Git, I find the hgignore file and add ‘.git’ to the glob section. It’s much easier to set up hg to ignore files before they are committed into the hg repository. I’ve forgotten in the past and have found myself trying to run ‘hg remove’ (I think) on all the extra files that I can then ignore in hgignore. Too much efforts, when I can start the process on the right foot with the correct command.

I then set up git to watch the project directory with a simple ‘git init’ command. Before I add or commit anything to the Git repo, I update the gitignore file to ignore all the Hg files by adding ‘.hg/‘. I can then safely run ‘git add .’ and ‘git commit -m “first message” ‘ without worrying about all the HG files. It seems to work, so why not both.