Tutorial: Introduction To Git

From Lorekeeper Wiki
Jump to navigation Jump to search

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!


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
SourceTree commit.png


Switching current head
Sourcetree switching head.png
SourceTree pushing pulling.png


Pulling and Pushing from/to remote Git
SourceTree pushpull1.png
SourceTree rqo0lqd83C.png


Creating a new Branch and Checkout
SourceTree KdDP7nHfqZ.png


Merging someone else's changes
SourceTree VHePgxpdFU.png


This warning is okay! That just shows you that you need to merge.
SourceTree Bo44Qi3JpK.png
Opening in VSC shows this, and you can select those options (or even type add something to one of the changes, THEN accept it! Most of the time youll be selecting incoming or current, rarely do you keep both)
SourceTree 6JDXgIhWLp.png


Gitkraken

Committing
Explorer ecExgoEfei.png


Switching current head
B7LJwTyr8m.png


Pulling and Pushing from/to remote Git
Gitkraken 8LbCjaWNuM.png


Creating a new Branch and Checkout
Gitkraken 2nsrtcM2pn.png


Merging someone else's changes
Gitkraken has a built in comparison tool! It's not as verbose as vsc, but it can work for simple comparisons
Gitkraken EV3KfQHCgN.png


Command-line

Committing
git statusgit status is your best friend. Always run it before committing.
git commit -am "<commit message>"


Switching current head
git log --onelineThis lists all your logs, and their SHA codes! Copy the one you want to switch to
git checkout <SHA>paste in the SHA code from before!


git checkout masterIf you want to switch back to master, you have to type this and NOT it's SHA code


Pulling and Pushing from/to remote Git
git push origin
git pull origin


Creating a new Branch and Checkout
git branch third-branchgit checkout third-branch unlike the gui programs, you have to also switch to it after creating it!


Merging someone else's changes
git pull originThis will generate the <<<<HEAD in the conflicting flile, and you can open it in VSC to accept the changes!
Code SxIEHq8etZ.png
git commit -am "mergegit push origin



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!

A fantastic interactive tutorial. Go through this if you're still having trouble grasping the concepts!

A LK guide on how to properly install extensions!!

Reference Guides

A really good and easy to read cheatsheet!

Something went wrong and you don't know how to fix it? This site has several helpful commands you can use to get back on track!