Tutorial: Introduction To Git
This guide is a work in progress!! Feel free to edit and fix any of my terminology or any other issues you may have. Or just add to this!
Contents
What is Git? How does it work?
Git is essentially a piece of software that saves all changes ever made to a file, but it can do so much more than just that. Let's break down the 5 common uses for Git.
Commits
Let's say you're a writer, and you want to save all of your drafts as you write and edit in case you want to roll back some of the changes. One way would be to manually save to separate files, such as draft1.doc, draft2.doc, ... draft242.doc...
, but with git, it handles it for you whenever you Commit your changes!
Each time you Commit your git directory a snapshot of the files that you have changed are saved, backing up the old changes at the same time! Instead of manually making copies of files or zipping up your entire folder, this is not only faster but more secure and flexible!
Switching current head.
What if you aren't satisfied with your current draft and want to roll back to an earlier version? Git has you covered! If you ever run into issues you can just jump back to an earlier Commit and continue from there!
Pulling and Pushing from/to remote Git
What if you want to back up your data to a remote server? Well that's also built into git! If you've ever heard of github or gitlab, they're sites made just for this (AND sharing/viewing code!)
Instead of something like dropbox which is automatic, git requires you to deliberately Push (upload) and Pull (download) whenever you want you update your files local or remote side.
Creating a new Branch and Checkout
What if you want to try to make some more drastic changes without having to keep track how many Commits you can create a copy of your current workspace, which is called Branching!
Each workspace in git is called a Branch, and creating a new branch is called Branching, and if you want to switch to a new branch, you have to Checkout that branch! The terms are weird, but it's not as complicated as it sounds!
Merging someone else's changes.
What if someone helped you with your writing and you want to combine it with yours? Instead of manually copy and pasting it, you can Pull their changes and Merge it into your file!
Even though I used writing a story for all of these examples, the primary way most people use it is for coding! (however plenty of people use it for writing too!)
Why is Git used for Lorekeeper?
Most if not all collaborative programming projects use a distributed version-control system like git to facilitate and keep track of changes to the codebase! Not only is it easy to learn and use, but it also keeps track of who pushed what changes! Without git, developing programs like Lorekeeper would be much, much harder than before.
Git examples in actual git programs
There are the above uses for git actually being used inside actual git programs! We'll be going through them in source-tree, gitkraken, and command-line!
But first, you may be wondering: what's the difference between all these programs?
The simple answer is GUI and compatibility. Sourcetree is the best choice for its simplicity, but users on oses other than windows 10 have had issues and switched to gitkraken instead. Why would you ever use command-line you ask? That's because git is actually a command-line program! All these programs are essentially just GUI's to make things easier if you aren't used to typing commands. You can do everything you can do in these programs through the command-line (and sometimes even more) so it's good to see the basic use-cases on that. Plus, you can even run these same commands through putty on your server!
Sourcetree
Committing
Switching current head
Pulling and Pushing from/to remote Git
Creating a new Branch and Checkout
Merging someone else's changes
Gitkraken
Committing
Switching current head
Pulling and Pushing from/to remote Git
Creating a new Branch and Checkout
Merging someone else's changes
Command-line
Committing
Switching current head
Pulling and Pushing from/to remote Git
Creating a new Branch and Checkout
Merging someone else's changes
Tips and Tricks
[WORK IN PROGRESS, FEEL FREE TO ADD SOME HERE]
Resources and Additional reading links
Tutorials
A great write up covering of the basics.
A great video covering the basics! Watch this if you're more of a audio learner!