Everyone’s usual go-to for making a new repo and storing code is Github, and it has loads of upsides, but if you don’t want that code publicly accessible, then you need to pay up. If you’re working on a solo project, and just want version history, branching, and peace of mind from having the code backed up until you’re ready to move on to a premium account on Github, you have a very fast & easy option to accomplish that:
git init --bare
That magic command is all it takes to turn an empty folder into a git repo that you can clone from, push to, manage branches, view your revisions & history, all on your local hard drive.
The concept is this, you use any of the cloud backup services you have, Google Drive, Dropbox, pCloud, doesn’t matter. You create the folder for your git repo inside of a folder that is always backed up to one of those services.
You can then go to the location on the hard drive where you want to have your working code stored and clone directly from the folder you ran the git init –bare command in and that’s it.
Here’s a complete step-by-step example where I want my repo backed up by pCloud but stored on my E drive where I want to keep my working project:
# Make the local git repo (this is using Git Bash) $ mkdir /p/pDrive/git-repos/my-project.git $ cd /p/pDrive/git-repos/my-project.git $ git init --bare >>> Initialized empty Git repository in P:/pDrive/git-repos/my-project.git/ # Clone the new repo in the location you want to do your work from $ cd /e/code $ git clone /p/pDrive/git-repos/my-project.git >>> Cloning into 'my-project'... >>> warning: You appear to have cloned an empty repository. >>> done. $ cd my-project/ # Here are the contents of our newly cloned repo $ ls -al >>> total 4 >>> drwxr-xr-x 1 Mike 197121 0 Jul 26 07:47 ./ >>> drwxr-xr-x 1 Mike 197121 0 Jul 26 07:47 ../ >>> drwxr-xr-x 1 Mike 197121 0 Jul 26 07:47 .git/ # Here are the remotes $ git remote -v >>> origin P:/pDrive/git-repos/my-project.git (fetch) >>> origin P:/pDrive/git-repos/my-project.git (push) # Let's make a commit, add some content and save the file $ nano Readme.md $ git status >>> On branch master >>> No commits yet >>> Untracked files: >>> (use "git add <file>..." to include in what will be committed) >>> Readme.md >>> nothing added to commit but untracked files present (use "git add" to track) $ git add Readme.md >>> warning: LF will be replaced by CRLF in Readme.md. >>> The file will have its original line endings in your working directory $ git commit -am "Adding readme" >>> [master (root-commit) 0455a96] Adding readme >>> 1 file changed, 1 insertion(+) >>> create mode 100644 Readme.md $ git push origin master >>> Enumerating objects: 3, done. >>> Counting objects: 100% (3/3), done. >>> Writing objects: 100% (3/3), 225 bytes | 225.00 KiB/s, done. >>> Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 >>> To P:/pDrive/git-repos/my-project.git >>> * [new branch] master -> master