Working with Git

Working with Git

Essential commands and procedures.

Working with Git

Git is an excellent distributed revision control tool. All my writing is done offline, using text files in Git repositories. This provides remote backup across any number of devices, with full revision control on all of them. If any device is lost, disabled, or broken, I can pick up without any loss (and with the complete revision history intact) from any of the other repositories.

I am far from proficient using Git. I only use about 20% of the total functionality of Git and usually manage my repositories with a client like Tower or Github Desktop. That said, these are the Git commands that I use most frequently when working “under the hood”.

Set up an existing directory as a Git repository:

git init <directory>

Set up a remote Git repository (to sync with an existing repository):

git init --bare <directory>

Note: if a remote repository is setup without the --bare use this to change it to a bare repository: git config --bool core.bare true

Add a remote repository:

git remote add myremote username@servername.com:directory/to/repository.git

Push the master branch to the new repository

git push myremote master