After playing around with git for a couple of months, I should have known better the first step of getting my project up and running. Turned out that I didn’t. That’s not okay, so I decided to write about the proper way of linking a local and remote repo together – I won’t make this mistake again!
But first, let me describe my erroneous workflow.
- Create a new Rails project. Running the following command created a new directory called
# inside my project folder $ rails new my_project -T -d postgresql --api
git initto add version control functionality.
Visit my GitHub account and create a new repo with the same project name,
my_project, initializing with a README (this was part of the problem!).
- Run the following command:
$ git remote add origin remote_repository_URL
- Then I checked out to a new branch called
setup, since my work pertained to installing gems and creating folder structures. Then I did git add, commit, and push these new changes to GitHub.
I did see a colored flash message of a new PR on GitHub. When I opened it though, I got a weird message:
There isn't anything to compare. master and setup are entirely different commit histories.
What?! I thought my local repo and remote repo in GitHub were in sync with each other. What went wrong?
After googling, I realized that my workflow was a bit out of order. So here is the proper way to do it (github help page).
- Create a new project on your local repo, and
git addall recent changes and
git committhem as “Initial commit”.
- Create a new repo on GitHub, WITHOUT README. Depending on whether
 Initialize with READMEis checked or not, you’ll be redirected to different pages. If unchecked, you will see a box with the header called
Quick setupon top of the page.
- Back in Terminal,
git remote add origin remote_repository_URL.
- Push the changes in local repo to GitHub,
git push -u origin master.
This above routine should be your second nature. Practice it early and often so that you won’t be hindered by initial setup issues.