What is Version Control??
generally, a large application is divided into many modules and to develop any large application there are many developers working at a time. So, version control has a critical role in that case. It generally helps you to manage and track changes to files like adding new files and reviewing any changes to the old code.[Git](git-scm.com "git")is one of the most famous version control systems.
Main features of version Control
Version control systems like git come with a lot of handy features that help in building a large-scale application and managing to collaborate on a project. the main features of a git are
- add new files
- remove files
- track any change to the old file
- keep a history of the files about the changes and collaborator history It basically works like a time machine that can go to the past and highlight the changes that what changes had been done by whom. There are some famous software platforms that help you host your code using version control systems like git those are Github
Getting Started with Git
Getting started with Git is very easy you just need to install git bash for your system. Some of the basic comments are that every version control system has are listed below
Git Command | Git Behavior |
status | Report the state of the files that are added |
add | To add the files at the staging area to make a commit |
commit | Store prepared changes in local revision history |
branch | Create local context for commits |
push | Upload commit history to GitHub/centralized Git host |
First Code push to Github
Git just helps you to version control files locally but to showcase software publically we require some of the VCS platforms like GitHub GitLab Bitbucket etc so let's see a step-by-step process to upload code in Github.
- These are standard steps that are mentioned by GitHub to create a new repository on the command line
git init git add README.md git commit -m "first commit" git branch -M main git remote add origin git@github.com:Dipanjansur/test.git git push -u origin main
- These are steps to push an existing repository from the command line
So let's understand these commends line by linegit remote add origin git@github.com:Dipanjansur/test.git git branch -M main git push -u origin main
git init
- This is to add the git VCS to the current directory. generally, git is not applied to the directory. To enable git tracking this commend is used
git add Readme . md
- In the GitHub community markdown files are used to generate a summary of the project. Git add is used to add the files to the staging area and now will track all the changes to the directory. to add all the files to the repository using
git add .
git commit -m "first commit"
- git commit will commit all the files that are in the staging area and will add a message to the commit to identify the purpose of the commit and to understand what changes are applied to the files.
git branch -M main
- A repository can have many branches which can contain many features branch and different types of versions so this will set the branch to main which is considered the best practice in the GitHub community
git remote add origin git @ github . com:{username}/{RepoName}.git
- to push a codebase which is the commit stage Git needs to know your remote location where the code should go this line helps git to understand that it will add a remote origin to the git and it will vary from the repository to repository
git push -u origin main
- now as git knows where to push the code remotely and knows which branch to use it is all set up to put the code at a remote repository. This is the final step to push a code .Sometimes git needs an auth-token to verify or can ask to re-login from the browser.