Git is currently the most popular implementation of a distributed version control system for tracking changes in computer files and coordinating work on those files among multiple people. Git originates from the Linux kernel development and was founded in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. It is primarily used for software development but it can be used to keep track of changes in any files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.
Git is not an acronym. ‘git’ is British slang for a dumb, annoying, or generally unpleasant person. The joke is that Linus Torvalds names his projects after himself, so he chooses ‘git’ as the name of the SCM he made.
Latest version of git is 2.19.1 (2018-09-27).
How to install git?
We set up an initial environment on the master branch and develop branch to merge our work. We use to create a different branch for different module work to track our work module wise.
Steps are as below :
- Create an issue on gitlab and note down issue number
- Open cmd/git bash and go on the particular project directory
- Go to branch (checkout branch) develop
- Create branch follow by issue number (i.e. issue number-Users, 1-Users)
Some common commands :
- git branch issue_number-branch_name – To create a new branch
- git checkout branch_name – To go on a particular branch
- git add . – To add all changes in that branch
- git commit -m “comment like whatever you have done” – To create a commit with a comment regarding work
- git commit -m “Completed Add User, Edit User work”
- git push origin branch_name – Push changes on a server
- git push origin 1-Users
- Then copy merge request link and create merge request from a browser. Ask project master to accept your changes so now all changes will be merged in develop branch.
- git status – It will show your list of file(s) on which you have done changes
- git pull – To fetch all latest changes of that branch
- git stash – To reverse changes
- git reset –hard – Discard local changes
Sometimes, you will face conflict issues. Follow below steps in that case :
- Add, commit, push in your branch
- Go to develop branch and use pull to get the latest changes
- Go to your branch and follow steps one by one
- git rebase develop – It will show you appropriate message whether conflicts are there or not. If no conflicts then go ahead to merge request. If there are conflicts then go ahead for next steps.
- git status – It will show you files in which you need to do some changes to solve conflicts. Keep relevant code from all files and remove other codes.
- git add . – Add rebase changes
- git rebase –continue – So, it will check again if there are more conflicts. If there are no changes then do add, commit and push. If changes are there then do git status, solve conflicts, git add and again git rebase –continue. Follow until you solve all conflicts.
Note :
- Always create a new branch from developing. Follow steps as below :
- git checkout develop – Go to branch develop
- git pull – Get all latest changes from developing
- git branch issue_number-branch_name – Create a new branch
- git checkout issue_number-branch_name – Now, start working
- Never work on develop branch. If you work by mistake then copy your changes somewhere, then use git stash so it will discard local changes. Now, create a new branch or go on your any existing branch and copy those changes and go ahead.