How to Create and Push to a Local Git Repository

I want to store this one for later so I’m posting it here. If you find it useful feel free to link to it.

I wanted to version some files I’m working on but didn’t want to use a git service like BitBucket, GitLab, etc. mainly because they are huge and I don’t want to wait for them to upload all the time or pay money for that.

In order to do that I created a git repository on a separate hard drive on my system. The first step is to initialize this.

I found help with doing that here.

From within Git Bash or whatever you happen to be using type these commands wherever you want to store your git repository:

git init --bare --shared=group local.git
cd local.git
git config receive.denyCurrentBranch ignore

See this answer from just above the other one for a description of what those commands do.

Also note that instead of the first command, since I’m working on my own, I can just type:

git init --bare local.git

Next, in your working folder where you have your files run these commands:

git init
git remote add local E:\local.git
git add -A
git commit -m 'Init'
git push local master

And that is it!

If you want to store your local.git folder in a subfolder then you can change E:\local.git to file:///e/subfolder/local.git. You can change it in your .git/config file directly if you like.

Now whenever you want to save your changes just run the last 3 lines again with a new commit message and hopefully it will go ok. If not then you may have some more digging in git to do.

Leave a Reply

Your email address will not be published. Required fields are marked *

*