For Windows:
Access the URL below and download the latest version:
Git Bash will be installed, which will allow manipulation of Git by command line.
For Mac:
It can be installed through the address below:
https://code.google.com/archive/p/git-osx-installer/
For Linux:
To install on Ubuntu or any Debian distribution, for example, just type in the terminal:
$ sudo apt-get install git
See command for other Linux distributions:
https://git-scm.com/download/linux
I. Basic settings
Initially, it's important to identify ourselves to Git. In a terminal, run the commands below, replacing them with your data:
$ git config --global user.name "XYZ"
$ git config --global user.email xyz@gmail.com
II. Creating a file for versioning
Let's train with a text file, for example. It could be your code file, of course. Create a file in your home folder called musics.txt
.
Inside the file, we can type the following content and save:
Let It Be (The Beatles)
Satisfaction (The Rolling Stones)
House Of The Rising Sun (The Animals)
Three excellent songs. I'm going to put one of them here just to relax a little:
Where is my home folder? Okay, on Linux, just type in the terminal:
$ echo ~
Result will come something like:
/home/xyz
III. Versioning the file with Git
1. Create a repository
Create a directory with the command:
$ mkdir songs
Now, access the created folder:
$ cd songs
This is a common folder. We need to turn it into a Git repository. To turn the current directory into a Git repository, simply run the git init command:
$ git init
As a result, something like this should appear:
Initialized empty Git repository in /home/xyz/songs/.git/
A hidden folder called .git
is created inside the directory.
2. Track the file
Let's analyze the status of the musics.txt
file in the repository. For this we use the command:
$ git status
The output should be:
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be
committed)
musics.txt
nothing added to commit but untracked files present (use
"git add" to track)
Git itself already provides some tips for you, how to use the git add command to add the file to the stage area.
In order for the file to be tracked, then let's run the suggested command:
$ git add musics.txt
Now, if we run git status
again, we get new output:
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: musics.txt
3. Write the file to the repository
To write the changes to the repository, we must run the command:
$ git commit -m "Initial music file"
The git commit command was invoked with the -m
option to inform the commit message. A way to organize and guide commits.
Now if we run git status
again, we get the output:
On branch master
nothing to commit, working directory clean
4. Change the file
Let's insert one more line in the musics.txt
file as a change:
Hey Joe (Jimi Hendrix)
Once we change the file, either adding or removing content, we need to check the status again:
$ git status
We will see that the git output shows the file as modified:
modified:musics.txt
To track the modification, we must run the command git add
again:
$ git add musics.txt
With the modification tracked, we can write it to the repository, with the git commit
command:
$ git commit -m "Inserting new music"
We should have an output similar to:
[master] Inserting new citation
1 file changed, 1 insertion(+)
5. Check the log
To check the recording history, we run the command:
$ git log
In Part 3, we are going to share the file on GitHub. See you soon.