Version Control and Basic Git and GitHub (for beginners)
As a developer or even as a tech savy person we should know what is version control. It really eases our life from maintaining school projects to managing big codebases.
In this blog basics will be discussed then in next blog advance commands will be covered.
Problems
When a programmer/developer starts his journey he use to keep all the programs and codes in a folder with a specific name in his disk. But after somedays he thinks of updating the code he again open that code and make some changes in that or copy the app then make some changes in that copy. Very Simple and relatable😅. Ya I also used to do it.
But lets think of some edge cases here of what things can happen in this phase.
- Everyone likes to have different versions of their app like v1 or v2. So if the app is very large in size and making copies will consume disk space.
- While updating the code if copy not made and we have made many changes in the code it's become very frustrating to delete all the code and write them from beginning. In big codebase it is nearly impossible.
- Also if suppose our disk gets corrupted we will loose our all data.
Version Control
Version Control is nothing but a practice or technique use to maintain your work and even your data (some extent).
Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake.
Basically only changes made from one version to another are saved not the whole code in this practice.
So no need to make multiple copies or no need to delete the whole codebase and modifications. You can rectify them with some single commands.
Generally we call each project folder a repository or repo .
Generally we use to maintain a local repo that is present in our system and maintained using any version control tool like git .
Another online repo is maintained in platform like github. We can copy the entire online repo with just come commands of git.
Git
Terminologies of git and its different spaces
- Working directory is the folder where we work with the code. Here the code of files are not tracked. Just which are added are just observed.
- Staging area is the space where actually every code is observed. We need to add our files to staging area from working directory first to observe them.
- Repository is the final area where the current stage of code will be saved if you want. We call this as commit . Commit is basically adding the files from staging area to repository.
- Checkout is basically taking files from repository to working directory
It is very to setup git. Just type download git in google and go with next next in the setup.
- To initialise git in a project
To setup a git to observe your project this is necessary.
git init
- To add files to staging area
Lets add all the files to the staging area to observe changes.
git add .
Lets add a specific file to the staging area to observe changes.
git add filelocation
-
To commit files
To commit files to save to repository. Files must
be added to staging area first then they can be commited
only
git commit -m "Commit Message"
So upto this we made a workflow.
These four commands are the basic 4 commands.
Although they are not enough in some scenario.
GitHub
Now it is not enough to save everything offline.
So its better to push your repository or the things that are commited
online
in a platform like github. GitHub even plays a big role in deployment.
It is very simple to use.
For using github first create an account in github.
- Connecting git and github(beginner friendly way)
- Create a repo in github.
- Copy the http url of the repo.
- Then run the commands below
git remote add URL-COPIED
git remote add origin
git push -u origin
Damn ❤️ Very Helpful, Keep up the good work❤️
ReplyDeleteThanks man... Keep supporting
ReplyDelete