Lets get started with Git
Git is a free and open source distributed version control system. It is used in team development , where in you can not only add files but also keep track of the status of those files. In short it is a powerful tool where in you can work parallelly and manage the projects as a team and a individual. Knowing to use Git is one of the most essential skill for a developer and it definitely adds value to your resume.
Setting up Git on your system
It is generally operated through the terminal. First step is that Git should be installed in your system. You can download it from the link given below.
You can verify weather your installation is successful or not by checking the version of Git in your computer. You can run the following command for the same.
git — version
You can also configure your name and email id as follows
git config — global user.name “Your name”
git config — global user.email “your_email@git.com”
Getting started
To get started we first need to initialize an empty git repository. Imagine a repository as a container for your project code. There are basically 2 repositories which are local repository(storing the code in your local machine)and remote repository(highly suitable for team works).So to initialize type in your command line as follows:
git init
Expected workflow
Step-1 : Making changes to the file as needed.
Firstly to add a file you need to run the following command in the command line.
git add file1_name,file2_name
Step-2 : Preparation to share those changes.
We usually share the file with a message. Which is called as commit. To commit your file with a message you can do the following:
git commit -m “message”
Step-3 : Share the changes
Now to share the file git uses something called as remote repository for storage. Now to register an already created repository in your system you can run the following:
git remote add remote_name remote_url
To share the files you need to upload it in the remote repository, this process is called “push”. For that you need to write the following code in your command line :
git push remote_name master
Now when it comes to my github in the test repository the file will be present there.
Here master is the branch. You can also add different branches in the repository by
git branch branch_name
You can change the repositories you work in by running the following:
git checkout branch_name
Merging and deleting the branches is also possible through the following codes respectively:
git merge branch_name
git branch -d branch_name
You can download the files committed by other developers by the method called as “Pull”. Where in you do the following:
git pull remote_name master
It is also important to clearly recognize your changes you made and select the efficient ones among them and then proceed to share among the developers.
Noticing your changes
There can be different changes made by you and the developers overtime, so git also provides you with tracking don your changes made by running the following command in your terminal:
git status
To see the detailed view of the changes made by your team you can type the following command where in the code after change appears in green and code before changes appears in red:
git diff
Points to ponder upon
- You can check the status of your modified files i.e. weather they are committed or not through “git status “ command where in not added files appear in red and added files appear in green.
- You should always write some good commit messages which are understandable by your team as well.
- You can as keep track of the different commits overtime by using the command “git log -p” and to exit from the command enter “q”.
Further learnings
To learn more about Git you can refer to git official documentation.