Git - some things you might want to know

Cleanup on Isle Git!

In case you get into a mess in Github (like some of us did) where you start getting fatal errors trying to pull from/push to github and you just want to start over, a clean slate, here is how to delete your repo locally and on Github.

Local Repo: in your project folder, remove your local repo by running… git rm -rf .git

This will remove the .git folder and you can start afresh from git init. (check ls -a for hidden files/folders to confirm that .git is gone).

GitHub: Open the main page for the repo you want to delete and click Settings and scroll down to Danger Zone and delete the repo. Make sure you have a backup (clone) if you need to as this can NOT be undone.

Private or Public Repo?

Private is also free (since 2020) but I have discovered several items you CANT do if you choose Private, like Insight Network which shows you branches and merges, so I would go public, just make sure (like I didnt) that confidential info is in an .env file and that one line in your .gitignore has .env so this doesnt go public. MailChimp and probably others WILL find and disable your API keys if they go public on github, but they kindly allow you to create new APIs!

TIP: When creating a repo on Github, just enter name, description and choose Public and do NOT check any of the checkboxes. Not checking them will create a new empty repo, while checking any of the checkboxes will INITIALIZE the repo (ie add content). This then requires a Pull request to update your local repo with the readme file. It is simpler to create the empty github repo and then follow the command line instructions to push a local repo. (See article below for more info.)

Out on a Limb and a Branch

Did you know in 2020 Github decided to change their default branch name to main from master. BUT Git local still has default branch name master. What difference does this make? Well two different branch names = two different branches so when you think youre only working on one branch you may be working on two, as I was and got confused (see Cleanup on Isle Git). It doesnt mention this in the course and if you look carefully, as I did the second time around, the course shows status “on branch master” and after commit shows (HEAD → master). I suspect when the course was first written Github and git (local) were both master. Since 2020 they are not.

Here is a great article I found on this. Git and Github, Master and Main. You draw your own conclusions but for me, I did a Cleanup on Isle Git! Then I started locally with git init and then I NAMED THE DEFAULT BRANCH to main to be consistent with Github. As the article says you can even define this globally so that all your git inits create the same name, main (using

git config -global init.defaultBranch main

). I have done this. Read the article!
Git - Master vs Main

Heroku Heroes
If you deploy to Heroku, you will likely at some point see an alert regarding “master” and “main” branch and they give info on using “main”.

Dont .gitignore this!
I thought I got it. You want git to ignore certain files / folders even so you put them into .gitignore and then git add . will ignore them, right? Wrong! git add . will add ALL files to the staging area.

git commit is the command that will pass over files/folders listed in .gitignore so that these do NOT go to your public repo on github.

So, what happens if you do this? Well, I did it with a mailchimp API and fortunately they check and disabled the api key and have an option on their site to create a new key.

If you do push a file to Github that you dont want there then you can delete the file or the entire repo if its just for testing and doesnt really matter.

Dont .env me!
Put all your confidential stuff in an .env file in the root of your local app folder. Then MAKE SURE you add .env to your .gitignore file. That way, your confidential stuff wont find its way to your local repo nor github nor heroku.

Use package DOTENV to simply convert your .env contents to environment variables and of course change your code to use same env variables.

And if you deploy to Heroku, they have a CONFIG option (Settings, Reveal Config vars) and you can set up the identical env variables from your .env file and your app will work same was as .env file enables it to work locally.

If you dont commit -m to git
That little “-m”! If you omit it then a VIM text editor will pop up and you CAN add a comment there and type .ql and press enter to quit and save. But it is easier to always add that -m “reason for commit message”.

If this helps you please upvote so it might catch some interest elsewhere or help others. Thanks.