Version Control — GitHub
May 22, 2022Keeping track of your code and its many versions
What is “version control”, and why should you care? Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. It, also known as source control. Version control systems are software tools that help software teams manage changes to source code over time. As development environments have accelerated, version control systems help software teams work faster and smarter. They are especially useful for development teams since they help them to reduce development time and increase successful deployments.
Two types of version control systems
- Centralized Version Control System (CVCS)
- Distributed Version Control System (DVCS)
Centralized Version Control System(CVCS)
Repository — The repository is act as a central server that could be local or remote which is directly connected to each of the programmer’s workstation. Local Repository is a offline version repository only available in our local machine. Remote Repository is a main repository and online version repository, example : GitHub
How to use version control ?
Download and Install Git — https://git-scm.com/downloads
First create an empty local repository on your local machine. Then open the terminal and change directory to the created repository in your local machine.
Create some files in to the repository namely readme.txt and test.py, These files are not a part of the repository, we should commit to the repository.
touch readme.txt
touch test.py
Mainly there are two areas in the repository. First is Staging & Index area ,it is a temporary area, second area is Actual repository area, it stores the different version of the codes. We use “git add .” command to add the files to the staging & indexing area in the repository. Then we should commit the files to the actual repository area, “git commit -m “first change" ” command to commit the files. when we commit each time it saves the different version of the code.
Use “git status” to check the status of the repository.
For every changes in the code or files, we have to commit each updates. For example we delete test.py file from the repository , we delete the test.py using
“git rm --cached test.py”
Then check the status of the repository,
Then commit the file to the repository, it overwrites the updated files.
git commit -m “deleted test.py”
What is Branches and why it is needed ?
A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master . As you start making commits, you’re given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically.
For example Many developers working on a same project, each person should commit each time after they made change. So that we actually do is working on branches.
Create a branch name called login
git branch login
Switch to master branch to login branch by using
git checkout login
After worked on the login branch saves and switch back to the master branch and then merge the login branch with the master(main branch). To merge use,
git merge login
Then push the local repository to the remote repository, example GitHub is the cloud based remote repository.
First create a repository name called ‘test’ in the GitHub,
To list available remote repositories use,
git remote
use the following command from the GitHub to push the local repository to the remote repository.
To create remote repository in the GitHub use,
git remote add origin https://github.com/vithujanS19/test.git
To push the local repository to the online remote repository(GitHub)
git push -u origin master
Some commands and functions in version control
0 comments