Git is the most widely used version control system. Git source project was developed in 2005 by Linus Torvalds, he is the creator of the linux operating kernel.
Benefits of version control ?
1. A complete change history of each and every file
2. Branching and merging – individuals can work in there branch and merge to common
3. Traceability – using it each change can be traced.
Git over SVN
Git supports branching and tagging unlike svn
Git ensures authentic content history of your source code.
Git Commands to setup new repository
Command line instructions
Git global setup
git config --global user.name "john"
git config --global user.email "john.******@gmail.com"
Create a new repository
git clone https://gitlab.com/johnDoe/web*****Project.git
cd web-tutorialsite
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/johnDoe/web*****Project.git
git add .
git commit -m "Initial commit"
git push -u origin master
Existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/johnDoe/web*****Project.git
git push -u origin --all
git push -u origin --tags
Git Command to point to another Repository
For example to point to a new repository, earlier being repo A and new one being repo B.
git remote set-url origin <repo B - url>
Git Command to force push
This is used when you want to push your fresh changes to any remote branch, neglecting others commits or code which are already there in the remote repository.
When to use : Situation comes when sometimes other contributors push in there changes to a branch in which you are also working on and they mess up the code. In short they messed up something which you don’t like or is wrong and changes are many, then a quick solution to this would be to overwrite there changes and push your code forcefully to the remote repo.
git push --force origin
Summary
In this tutorial we looked into the history of git, its benefits and learnt to create a new git repository use what.
Hope you liked it!