Git is version control tool for track, monitor and collaborate code. and it does not require codeing and is useful for developers, designer, project managers, students, teachers and for anyone who would like to learn.
Core competencies:
1. Prerequisite - Bash terminal and a text editor
2. Important terminal commands
3. Git commands and using git locally
4. git remotes and github
Installation:
MaC OS:
Open terminal and run below command
$xcode-select --install
It will pop up a message to install xcode command line tool, click on install and agree.
To test it run the command "git" on the terminal and you will see below which shows that the git has been installed.
Linux/Ubuntu:
To install git on Linux run below command:
$ sudo apt-get update
$ sudo apt-get install git
$ git --version
Download and install sublime text or any of your favorite text editor.
Windows:
To install for windows OS follow the link Git - Downloading Package (git-scm.com).
Basic terminal commands will be used:
pwd- check the current directory
ls - list directories
cd - Change Direcotry
touch- create file
mkdir- create directory
Create first git repository:
$mkdir GitProject1 //create folder GitProject
$cd GitProject1 //to change local directory to GitProject1
$touch myFile.txt //create an empty file
Open the file myFile.txt in your favourite editor and write some text and save it, we will be using vi editor to dot it:
$vi myFile.txt
//Press i in the keyboard after above command to make it insert mode and type "Hello World". Press Esc+:x and press enter the file will be saved.
Below is the file content:
Now run the command git init from inside the GitProject1 directory
1. git init: to initialize a git repository.
Run below command to see the git folders initialized under GitProject1 directory
$ls -a
As we were successfully able to initialize git repository, now we will use below commands for further actions:
1. git status : to check the status of the git repository, what branch you are on and tracked/un-tracked files.
We can see we have one un-tracked file myFile.txt which we will be tracking.
2. git add : to add the file to the staging for tracking purpose
As you can see, the file is added to the staging, now we can run the status command to see the tracking status.
From the above screenshot, you can see that we have changes to be committed under the file myFile.txt.
3. git commit -m "initial-commit" : to commit the changes
4. git log: to check the latest commits and the changes made to the repository
5. Making an update to existing file
Open the file in your preferred editor and update the file, we have used vi editor.
Once the changes are updated in the file, run the command get status to verify the changes to be staged.
As we have made changes to the file, we need to run git add command to add these changes to the staging.
After adding the file for the changes, we can run the status command again to see that the changes are ready to commit.
Next run the commit command and check the status of the file.
At the end we can run the git log command to see the changes/commits made to the project as per above screenshot.