git branches following me whenever I create new directories
After running into a few problems trying to push a new project (just one test file) to a new repository on github, I discovered that I’ve seemed to have made a huge blunder with git in that I have a project and branches following me around whenever I create new directories on my mac.
For example, I create a new directory in the sites folder of my mac
cd sites me$ mkdir mynewdirectory
If I do ‘git branch’ from the sites directory, it shows this
* master refactor
If I recall correctly, this master and refactor branch seems to be from a project i was working on a few weeks go.
If I cd into mynewdirectory and do ‘git branch’ I get the same result
git branch * master refactor
I then did ‘git status’ and got a very long list of
a) Changes not staged for commit; and b) Untracked files
These are all obviously unrelated to the new project i want to start, and I’m guessing is part of the reason why I had trouble pushing to a new remote origin.
Is there a way that I can get rid of all this while doing the least amount of harm?
2 Solutions collect form web for “git branches following me whenever I create new directories”
It sounds like you have initialized a Git repo in either your home directory (
~) or else the parent of all the directories you’re creating subdirectories in. If you’re in a subdirectory of a Git repo, you can get the root directory of the repo using
$ git rev-parse --show-toplevel
You probably don’t want to have your whole home directory and all of your files within be tracked in a Git repo, so I’d recommend moving that directory aside (e.g.,
mv ~/.git ~/.git.old if the repo is in your home directory) temporarily and create more focused repos for each project you want stored in Git. Once you’ve renamed the old repo, you should no longer have it interfering with your subdirectories and you can use
git init as normal to create per-project repos.
I said “temporarily” above because, if you have committed anything to that repo that you don’t want to permanently delete, you probably will want to copy it into a new repo or someplace else so you don’t lose it. One way to do that would be to move that old
.git directory into a new subdirectory from which you can pull out the stuff you want to store elsewhere, and once you’ve moved everything out you can delete the subdirectory. For example:
mkdir old_home_repo mv ~/.git ~/old_home_repo cd old_home_repo git checkout -- . # this will bring the files that were in the repo back into this directory # copy files out of this dir, into new places you want to keep them permanently cd .. rm -rf old_home_repo
if u have initiated git in your sites folder then you will get that refactor branch in all the subdirectories.