Sometimes you may need to keep code in a Git repo, but don’t have a nice web based backend like GitHub available yet to push your source into. A workaround can be to start with a file based repo that you can later easily push to a backend when you have one available. While you won’t have the nice web based repository view associated with many of these backends, you at least get the full Git command line.
All you need is the Git command line client to get started. Windows users can get it from git-scm.com and then use the Git-Bash command line client to manage their Git repositories.
At the time of this writing, I was using the StefanScherer/windows_10 VM image for VirtualBox from Vagrant Cloud, hence the vagrant user in the example paths.
Linux users can install Git from their distro; using the Git-Bash console in Windows has the same look and feel as Linux users using Git from Bash.
$ mkdir -p ~/repos/my-project $ cd ~/repos/my-project $ git init --bare
For Windows 10 users, this created a directory in your home folder for the vagrant account C:\Users\vagrant\repos\my-project. Next, figure out where you want to checkout your code to.
mkdir ~/projects cd ~/projects git clone file:///c/Users/vagrant/repos/my-project
This gave us a checkout directory in C:\Users\vagrant\projects\my-project. You may get the “warning: You appear to have cloned an empty repository.” message, nothing wrong here as this is exactly what you just did.
In the directory where you cloned the empty repo, you add files from an existing project or create new ones, whatever- this is your development directory. Then when your are ready for your initial push:
$ git add . $ git commit -m 'initial revision' $ git push
You have just done your first push to your upstream file based repo in C:\Users\vagrant\repos\my-project. You work with it just like one cloned from a backend like GitHub.
Pushing To Remote Backend
When your backend is set up and you are ready to push to a remote repository, just create a new repository on your backend. Using the remote URL, push the bare file based repo as shown in the example below:
$ cd ~/repos/my-project $ git push --mirror firstname.lastname@example.org/someusername/my-project.git
The URI following –mirror will different, depending on where and what your backend is.