Difference between revisions of "Tutorial: Introduction To Git"

From Lorekeeper Wiki
Jump to navigation Jump to search
m
Tag: 2017 source edit
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
 
===What is Git? How does it work?===
 
===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 7 common uses for Git.
+
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.
 
<br />
 
<br />
  
Line 65: Line 65:
  
 
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!)  
 
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!)  
 +
 +
  
 
<br />
 
<br />
Line 70: Line 72:
 
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.
 
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!
 +
<br />
 +
 +
==== Sourcetree ====
 +
 +
===== Committing =====
 +
[[File:SourceTree commit.png|center|thumb|808x808px]]
 +
<br />
 +
 +
===== Switching current head =====
 +
[[File:Sourcetree switching head.png|center|thumb|799x799px]]
 +
[[File:SourceTree pushing pulling.png|center|frame]]
 +
<br />
 +
 +
===== Pulling and Pushing from/to remote Git =====
 +
[[File:SourceTree pushpull1.png|center|thumb|820x820px]]
 +
[[File:SourceTree rqo0lqd83C.png|center|thumb|828x828px]]
 +
<br />
 +
 +
===== Creating a new Branch and Checkout =====
 +
[[File:SourceTree KdDP7nHfqZ.png|center|thumb|839x839px]]
 +
 +
 +
===== Merging someone else's changes =====
 +
[[File:SourceTree VHePgxpdFU.png|center|thumb|844x844px]]
 +
<br />
 +
[[File:SourceTree IhDdvxPC8C.png|center|frame|This warning is okay! That just shows you that you need to merge.]]
 +
[[File:SourceTree Bo44Qi3JpK.png|center|thumb|824x824px]]
 +
[[File:Code EjIbcVd1FY.png|center|thumb|869x869px|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)]]
 +
[[File:SourceTree 6JDXgIhWLp.png|center|thumb|878x878px]]
 +
<br />
 +
 +
==== Gitkraken ====
 +
 +
===== Committing =====
 +
[[File:Explorer ecExgoEfei.png|center|thumb|892x892px]]
 +
<br />
 +
 +
===== Switching current head =====
 +
[[File:B7LJwTyr8m.png|center|thumb|905x905px]]
 +
<br />
 +
 +
===== Pulling and Pushing from/to remote Git =====
 +
[[File:Gitkraken 8LbCjaWNuM.png|center|thumb|911x911px]]
 +
<br />
 +
 +
===== Creating a new Branch and Checkout =====
 +
[[File:Gitkraken 2nsrtcM2pn.png|center|thumb|905x905px]]
 +
<br />
 +
 +
===== Merging someone else's changes =====
 +
[[File:Gitkraken CwIdbjU3Wu.png|center|thumb|898x898px|Gitkraken has a built in comparison tool! It's not as verbose as vsc, but it can work for simple comparisons]]
 +
[[File:Gitkraken EV3KfQHCgN.png|center|thumb|908x908px]]
 +
 +
 +
==== Command-line ====
 +
 +
===== Committing =====
 +
[[File:Mintty 1b98i39yxq.png|center|frame|<code>git status</code>git status is your best friend. Always run it before committing.]]
 +
[[File:Mintty EjPaiq7MiX.png|center|frame|<code>git commit -am "<commit message>"</code>]]
 +
<br />
 +
 +
===== Switching current head =====
 +
[[File:Mintty qwLh0ooBFT.png|center|frame|<code>git log --oneline</code>This lists all your logs, and their SHA codes! Copy the one you want to switch to]]
 +
[[File:Explorer ybSJ3m3A06.png|center|frame|<code>git checkout <SHA></code>paste in the SHA code from before!]]
 +
<br />
 +
[[File:Mintty thH5c3tyvT.png|center|frame|<code>git checkout master</code>If you want to switch back to master, you have to type this and NOT it's SHA code]]
 +
<br />
 +
 +
===== Pulling and Pushing from/to remote Git =====
 +
[[File:Mintty yfIJS5u9E2.png|center|frame|<code>git push origin</code>]]
 +
[[File:Firefox ZgFELHx6Hr.png|center|frame|<code>git pull origin</code>]]
 +
<br />
 +
 +
===== Creating a new Branch and Checkout =====
 +
[[File:Firefox ro0ySwHl3g.png|center|frame|<code>git branch third-branch</code><code>git checkout third-branch</code>
 +
 +
unlike the gui programs, you have to also switch to it after creating it!]]
 +
<br />
 +
 +
===== Merging someone else's changes =====
 +
[[File:Mintty 8DV3eEX1sP.png|center|frame|<code>git pull origin</code>This will generate the <<<<HEAD in the conflicting flile, and you can open it in VSC to accept the changes!]]
 +
[[File:Code SxIEHq8etZ.png|center|thumb|947x947px]]
 +
[[File:Code KFHrtoPmpk.png|center|frame|<code>git commit -am "merge</code><code>git push origin</code>]]
 +
 +
 +
 +
<br />
 
===Tips and Tricks===
 
===Tips and Tricks===
 
[WORK IN PROGRESS, FEEL FREE TO ADD SOME HERE]
 
[WORK IN PROGRESS, FEEL FREE TO ADD SOME HERE]
Line 81: Line 179:
  
 
[https://learngitbranching.js.org/?locale=en_US A fantastic interactive tutorial. Go through this if you're still having trouble grasping the concepts!]
 
[https://learngitbranching.js.org/?locale=en_US A fantastic interactive tutorial. Go through this if you're still having trouble grasping the concepts!]
 +
 +
[http://wiki.lorekeeper.me/index.php?title=Tutorial:_Installing_Extensions A LK guide on how to properly install extensions!!]
  
 
====Reference Guides====
 
====Reference Guides====
Line 87: Line 187:
  
 
[https://ohshitgit.com/ 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!]
 
[https://ohshitgit.com/ 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!]
 +
 +
[[Category:Community Tutorials]]

Latest revision as of 15:58, 9 February 2021

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!