Linux Command Line Tutorial For Git
Publisher: Psychz Networks, February 11,2019For creating your identity on GIT you need to have Git on your system. If you have already installed Git on your system, kindly follow the tutorial below.
If not, you can find the steps for installing Git on your system (CentOS 7) on the following link https://www.psychz.net/client/kb/en/how-to-install-git-on-centos-7.html
Now, since you have Git on your system, you’ll want to do a few things to customize your Git environment. We will learn how to create your Identity on Git.
Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates.
How to create your identity on Git
First, you need to set your user name and email address with Git.
Note: Your username and email id are very important as every Git commit you to make uses this information.
git config --global user.name "your_name"
git config --global user.email your_email@abc.co
Checking your Git setting
To check your Git setting, issue the following command in your terminal.
git config --list
Cloning a Git repository
First, you must clone the git repository for your project to start with and only then you can commit your changes.
git clone https://158.179.XXX.XXX/demo/abc.git
With the help of the above command, you can clone a Git repo on a server. Here we specified the server IP address along with the path and 'abc.git' is the name.
Initializing a new Git repository
If you want to start your own git repository server for your codebase, issue the following command
git init
This will initiate a new git repository and the machine/host can be now used as a git repository server for that particular codebase. You can access the newly created repository by using the host’s IP or hostname.
Adding a new file to Git repository
Let us now see how to add a file to our newly created Git repo.
Before we create a demo file, you must go to your working folder and run following command
vim demo.txt
Add the following line to the demo.txt file.
"This is a demo copy of your demo file."
NOTE: Type ":wq" to save and exit
Our demo file has been created. Next, add this newly created file to the index of the Git repo by issuing
git
add demo.txt
Now, we need to commit this to your Git repo. This can be done
git commit
This will add the file “demo.txt” with its file content.
Push the changes to the repository
git push
This will push the changes into the master branch.
Deleting a file from Git
To delete a file from Git just do the following one after another.
git rm demo.txt
git commit -m "demo.txt file removed"
git push
You are done removing demo.txt from your git repository.