Version Control System (VSC)
Aman Pratap Singh
C++ || JavaScript || Web Development || MERN || DSA || Btech Student
What is Version?
So when we release any application we release it with minimal application uses for our users and later keep on updating it with new features. Once we are complete with building one complete ‘milestone’. Now a Milestone is when we add few features to the existing application fix the bugs and a new stable application with change or added features is a milestone. This milestone is then released in the form of versions.
Applications being updated on long terms can have many versions actually a whole set of version history. And we can come up with situations where the new updated version is not much stable and want to revert back to the older stable version. That’s when our Version control System comes into picture.
Its not over here, now one application is not build by any one person its the collaborative effort of whole bunch of people working and building few features and contributing in the project. Its not like I build one page of the project and other page is build by my fellow mate and we just share that information over mails to test the things this is not done.
That’s why we have a bunch of tool that help us to do Version control and provides us an environment where we can have a collaborative coding contributions.
What is Git?
The simple definition of git can be a Version Control System with whose help you can manage different version’s of a piece of code. You can understand it like you and your friend working on a project and makes a new feature for your project even though a simple one still its the new version of the project on the small scale and git helps to manage it efficiently on a very high scale.
Git is a free and open source application. One best part of git is its not a programming language so need not to worry of learning a new language more and less its like a tool. Example → We all have worked with power points where we create ppts its too a tool where we just want to know the steps to add a slide. In a similar way git is merely a tool where you just need to learn how to use it rather going inside of creating and thinking of logic how is it doing it.
Difference Between Git and GitHub -
So Git is a Version Control System and just like Git we have other VSC like Mercurial. Whereas Github is absolutely different then Git. Github is a Online tool for collaboration for Open soucre or Close source contributions. Github itself doesn’t do version control for you if you don’t have a .git file(Internally github uses git). Github just harness the power of git or similar VSC. Its an online platform where we have our code being published on the internet which manages our codes version just like VSC and instead of sharing the code on a private network we have made it on internet where people can come and have collaborative contribution its like a GUI interface.
Github have some additional feature like -
Git Config →
If you have installed the git you can test it. Open the terminal it can be gitBash Terminal or a window’s PowerShell Terminal or even imacTerminal and run these commands to check you have successfully installed it or not.
This will show the version of git in your system
git --version
git --config list
`
- to check your email and credential whether they have been setuped properly or not.
`
Git Commands
1.) Initialising Git →
git init
2.) Checking the status of the files →
git status
`
- Helps in tracking the files whether they are in the stagged area or working area.
`
There are Three areas where our file changes can reside.
So any file change we do might lie in one of these areas.
Working Area →
Currently if we create a file or do any changes which is not been tracked by git is in the working area. Tracking means git doesn’t know that whether these changes will or will not go into the next version as not being tracked right not. A file in working area is considered to be not in the staging area. When we do git status and see a bunch of untracked file then these untracked files are said to be in Working Area. You manually need to tell to git that which files you want to start tracking that will go into the new versions. As there could be log files or even some temporary files you need not to track those. So git itself doesn’t tracks file you need to tell it.
Staging Area →
All the files inside the Staged Area or Staging area are going to be the part of the next version that we will create. This staging area is the place where git knows what changes will be done from the last version to the next version. Tracks the file changes between the two commits.
3.) Adding a file in the staging Area →
git add <file-name>
git rm --cached <file-name>
git add <file1> <file2> <file3> ...
`
- All these files will get added to the stagging area.
`
git add .
Repository Area →
This area actually contains the details of all your previous registered version. And the files in this area, git already manages them and knows their version history.
领英推荐
4.) Creating a Version Or adding file in Repository Area →
git commit
`
- You register the staging area files to get commit through this command. And create a new version out of it.
- Once you enter it will show a terminal based text editor(actually its a vim editor).
- And expects you to enter a message before commiting the changes.
`
git commit -m "<Your Commit message>"
5.) To look your commit or log history you can do something like →
git log
`
- Will show you the whole commit history, By whom what time a commit was made.
`
git restore <file-name>
6.) What if you want to revert back a file from stagging Area back to Working Area →
git restore --stagged <file-name>
Difference between the git rm and git restore →
git rm --cached <file-name>
7.) We can also have a look on the difference between the two commits →
git diff <hash-id-second-commit> <hash-id-first-commit>
8.) Connecting Your local git repository to your Github repository →
git remote add origin <Url-of-github-repo>
`
- This will just link our local repo to the github repo.
- Here instead of origin we can write anything its just a name of the remote connection most of the users use origin
`
git remote
`
- Will list all the remote connection.
`
git remote rm <name-of-remote-connection>
git remote rename <old-name> <new-name>
9.) Uploading changes from the local repository to the github repository →
git push origin master
10.) Downloading the latest changes made to the repository by the contributors →
git pull <remote-name> <branch-name>
Recommended Practice to do →
It is recommended to add the files and push a commit in this sequence making a pull request before doing a push request.
Merge Conflicts →