Git is a version control system to track changes to software and code. It enables groups of people to work together efficiently on big projects.
Instead of sharing the whole files with every person that needs to work on the project, you can instead have one single repository where the entire project is located. This way, anyone who needs the latest version can always have access to it.
So, what is the difference between GIT and GitHub?
GitHub is the cloud-based hosting service where all Git repositories are stored and managed.
Another way of thinking about it is YouTube. Think of videos themselves as GIT, and the place where all the videos are stored in the YouTube servers themselves are like GitHub.
#!#
Before we begin, you will need to understand how Linux and bash scripting works. If you want to follow along, I highly recommend you install Windows Subsystem for Linux (WSL) from the official website here.
This eliminates the need to run your own virtualization (virtual machine such as VirtualBox or VMware) and can save you a lot of time from booting it up each time.
WSL is quite literally running a Linux operating system just in Command Line Interface (CLI) format. You won't get all the drag-and-drop features or be able to run complex games like DotA2, but it will be sufficient for using GIT.
Now the fun stuff
1) Let's first create a text file.
2) Let's run git init which will set up the tools that Git needs for tracking any changes to it.
3) Next, we will use git status to see what we need to focus on. Here we see that the text file we made on step 1 is recognized, but we have not properly added it to Git to track any changes.
4) Type git add scene-1.txt. If you don't get any errors, then that is a good thing. Check the status again with git status. We see in green color text that the file has been successfully added.
5) Now let's use a built-in text editor VIM. Do vim scene-1.txt. You won't be able to write any text in it yet.
To do so, type colon ( : ) then the letter i. Just like this :i.
The colon is for issuing commands into VIM, and i stands for insertion mode, which will allow you to insert text into the text file.
Now below line 1, type the following Dumblediff: I should've known you would be here, Professor McGonagit.
Press the Esc key on your keyboard, colon, the letter w, the letter q, then enter. w stands for write q stands for quit
6) Now we are going to look for any changes in the file we first had in scene-1.txt. To do this, we type in git diff scene-1.txt.
Note: git diff will not work if you git add before using the command.
7) To add this updated file to Git, you know what to do.
8) In order to publish our final draft to GitHub, we need to do a commit. Just like the definition of commit, we are making a commitment to upload our file to GitHub.
Type git commit -m "Completed first line of dialogue".
-m (dash and the letter m) represents the message you want to put in to remind yourself why you made a certain change.
If you only write git commit, a text editor will open telling you to write something.
If you don't want to write anything, you can just leave the message blank between the two quotes like this: git commit -m ""
However, it is highly recommended to document everything you do so other people can also understand what you have done.
Here are some standard conventions when writing commit messages:
- Must be in quotation marks
- Written in the present tense
- Should be brief (50 characters or less)
#!#
If you get this message
Then follow the instructions and add your Name and Email. You do not have to put your real name.
9) Now, if you need to refer to a previous version of your Git project, you can write git log. You will get an output like this
The long hexadecimal after commit starting with 731e... is 40 characters long. This is called Secure Hash Algorithms (SHA) which is used to verify the integrity of your data and identify your branch properly. Every part of the tree has its own SHA.
#!#
Let's recap everything from this article!
1) git init allows you to create a new repository in Git.
2) git status will give you the latest information about the contents in your current directory and stage.
3) git add lets you add files from your directory before committing it (thus, it is in the staging area now).
4) git diff shows you the difference between the two codes after you make changes.
5) git commit will let you upload to GitHub and make changes permanent.
6) git log will tell you all the commits you have done so far.
source: codecademy.com/learn/learn-git