Figuring Out a git and Rails API Setup Issue

Scott H Lee
3 min readFeb 25, 2021

I recently had to setup a Full-Stack application using Rails on the backend and React for the frontend. As part of the project we were prompted to get into good coding habits. That meant separating the frontend code and backend code into different github repositories. This seemed pretty straight forward, and I promptly went through my usual steps for creating a new github repository. I went to my github account and created two new repositories. Once these were created and I had created two separate folders on my local machine, I cloned the frontend and backend repositories down to my laptop. All good!

The frontend steps went off without a hitch: clone it down, create a branch, make some changes, make a commit, merge the branch with master and push it up. I now had a React frontend started and I was on my way.

Programming at lightening speed!

The backend was a different story. It was all going well: clone down the new repository, create a branch, create a new Rails server using a string of options designed to create a lean server without all of the fluff, git status — red folder — all good!, git add……………………………………..WRONG! Eventually I will recreate the setup so that I can fill in the error messages here.

On branch scott-0224-1200
Untracked files:
(use "git add <file>..." to include in what will be committed)
fantasy-congress-backend/nothing added to commit but untracked files present (use "git add" to track)

Things stopped working as planned and error messages filled the screen. “…not a git repository”. I could not add files, so I could not commit files! The next folder down in the directory was created by Rails, so it shouldn’t be a problem, but I typed git status just for grins. Lots of red, but this should not be here. It should be one folder up in the directory. …git add…..

But how did this happen? As it turns out, the new Rails implementation had created a new git repo inside of my git repo and on top of that, it had hidden the.git file. Enter the Rails options cheatsheet, and one answer.

The Rails Options Cheatsheet

You can turn off the option to create a git repository:

rails new --api <project name> --skip git

After completely wiping out my Rails directories and deleting my rails git repo, I started fresh. Success! I could git add, git commit, git push, git branch at will. I ended up adding back a .gitignore file so that I could hide an API key.

As an addendum, and after reading some Slack threads, I could have saved a lot of trouble by moving to the Rails directory and typing:

rm -rf .git

which would have removed the .git file and allowed .git from my upper level directory to work.

--

--