git init to git in it
Except when you clone…
So “git init to git in it except when you clone…”
“git init” initializes a repository for you to work in on your computer. This will allow you to make whatever changes you want to make before you stage, commit, and, potentially, push them. So when I say, “git init to git in it,” what I’m referring to is that by initializing this repository, you are now working inside of it. All of the following git commands you use will be inside of this repository until you establish a new repository, which as you’ll see below can prove treacherous illustrated by my example.
So what about cloning? “Except when you clone…” was part of that. Let’s get in it — again pun intended… these are horrible puns, I know, but that’s the beauty of the pun… they’re best when they’re awful.
So when you clone, it automatically places you in your repository that you’ll be git’ing in. If you were to enter in “git init” after cloning. You would enter into what’s called “Gitception”. You can probably guess what that means — a git inside of a git ad infinitum.
Let’s go ahead and work through an example of what I’m talking about complete with pictures.
So we can create a directory on our desktop. For this example I’ll call it, “git_init_mistake”.
Next we’ll go ahead and fork and clone a repo just to see where everything stands pre-git init. Then, we’ll “git init”.
As you can see, the repo is present, but look what happens when I type “ls -la” into the command line revealing the hidden files.
We have a .git file already. This is because the repo was cloned, and the repo was already git-initiated.
Now what happens if I run “git init” and a “ls -la” in a directory inside of this git-initiated directory?
We now have a git-initiated directory inside of a git initiated directory.
The problem with this is that when we try to push to GitHub or any remote repo, we’re going to experience fatal errors. The local machine as well as the server of the remote repository has no clue what to do with a git repo inside of a git repo and will crash the request to push it.
This is a nuisance that’s best left avoided. All of this could’ve been avoided had you not run “git init” inside your git-initiated cloned repository. So just remember… git init to git in it, except when you clone.