In this section we will learn about Git and its command line fundamentals. Lets first by learning what is Git.
Central VCS
Git is a Distributed version control system unlike the Central VCS where a server containing database is located in a single place and computers or users try to access that single Server. This becomes problem if something happens to the server and non of the users will not be access them.
Distributed VCS
In Distributed VCS where every users have a local copy of the repository containing all of the information of those remote repository. This helps the developer to have an access entire backup of the remote repository thus making sure their uninterpreted work in case of network problem or problem in remote server.
Installation of Git
I. Visit their official link https://git-scm.com/ and download appropriate package based on your operating system.
II. Run the downloaded package and proceed through their simple installation steps. One the installation is completed, navigate to the list of installed programs to find Git Bash and Git UI installed. The best way to check if the installation is successful by entering below command
git --version
Configuring Git
Now lets configure our Git, this is to let other developer or people know and differentiate the changes we have made and there are lot of configuration but here we will just configure username and email for the identification.
I. Configuring username and email by using below command,
git config --global user.name "Prathap Dominicsavio"
git config --global user.email "prathapdom@gmail.com"
II. Now let us see the changes we have made using the following command,
git config --list
The values displayed in these list are based on the changes made by users so it will vary between users.
When using Git, we face two scenarios which are applying git to tract changes in existing projects and to work with projects on remote server. Lets start with how to apply git to our existing projects.
Git on Existing Projects
Navigate to your project repository and type in the following command.
git init
This will create a folder named .git onto out working directory. Similarly we can remove those git monitoring by simply delete or remove .git folder by using below command.
rm -rf .git
To know the current status of the git on our working directory simply type in the bellow command.
git status
When working with our project we usually end up configuring the project based on our reference and it it best to avoid commit those preference in it. To go that we have to create a file named .gitignore and as the name suggest what it does is that it ignores all the directories or file (accepts wildcard) provided in it.
Simply create a file and add in the file name which you want to ignore and view the status. Now you won't be able to find your file in the staging area.
touch .gitignore
git status
To add everything into the staging are just type in the below command,
git add -A
And sequentially commit those changes in the staging area by just passing the following command along with commit message.
git commit -m "<commit message>"
Before commit if you wish to remove the files from the staging area, type in the bellow command.
git reset <file name>
So far we have performed a list of operation on our project by staging the changes. These are logged and if you wish to view them simple type in,
git log
This will provide information on the developer who has made the change and on what he has made change.
Projects on remote server
First we have to clone a project from remote server to our local system. To do that type in the below command,
git clone <URL> <Destination on the system>
Now to confirms and view information on our clone we type in anyone of the following command,
git remote -v
git branch -a
If you have made a change in the file after cloning which is a change in the file and now we can you a command in git to find out what exactly begin changed using the command
git diff
This will visually display the changes in the terminal like a Worktree. After committing this changes we need to push them to the remote server as we know that by committing we only did save changes in our local system. To push changes to remote server, type in the below command.
git push origin master
Similarly pull by using,
git push origin master
P