Day 8 of #90daysofdevops
Hey Techies! Welcome to this blog
In this blog, we are going to discuss Git and GitHub for DevOps engineers.
What is Git?
Git is a distributed version control system. Git is an open-source version control system (VCS) that enables you to store code, track revision history, merge code changes, and revert to earlier code versions when needed. Git stores your source code and its full development history locally in a repository. It helps in coordinating work amongst several people in a project and tracks progress over time. Unlike the centralized version control system, Git branches can be easily merged.
What is GitHub?
GitHub is a code hosting platform for version control and collaboration. GitHub provides distributed version controls geared towards tracking and managing changes to software code.
What is Version Control? How many types of version controls do we have?
Version control systems are a category of software tools that help in recording changes made to files by keeping track of modifications done in the code.
There are two main types of version control systems: centralized version control systems (CVCS) and distributed version control systems (DVCS).
Centralized Version Control System:
Note:-
It is not locally available, meaning we've always needed to be connected to a network to perform any action.
Since everything is centralized, if the central server fails, you will lose the entire data.
Distributed Version Control System:
Note:-
- In DVCS, every contributor has a local copy, or 'clone' of the main repository i.e., everyone maintains a local repository of their own, which contains all the files & metadata present in the main repository.
Why do we use distributed version control over centralized version control?
Task:
- Install Git on your computer and create your account or you can log in to your existing account.
Click on the '+' sign on the top right side and select 'New Repository' to create a repository.
Enter the name of your repository and, optionally, add a description.
Decide whether you want the repository to be public (visible to everyone) or private (accessible only to you and collaborators).
Note-:You can also initialize the repository with a README file, which helps start a new project.
Go to the main branch of repo and copy the repo URL.
Now go to the terminal and make a folder with the name Demo-github using the command
mkdir Demo-github
To clone the repo to the local terminal enter the command
git clone <repo-url>
mkdir Demo-github
cd Demo-github
git clone <repo-url>
- The code is cloned to local as we can see in the above snapsot.
Make some changes to a file in the repository and commit them to the repository using Git.
- Open your terminal or command prompt and navigate to the directory of the cloned repository using the cd command.
cd demo-Github
- Create a new file and perform all Git operations in the terminal.
- use git init
command to initialize the git repo.
- using touch <filename>
command to create an empty file and then use cat > <filename>
command to add some content to it.
- use git status
command to check the status of the repo.
- we can see that files abcd.txt and text.txt are created and untracked.
- using git add <filename>
command to track it and save it to git repo.
- use git commit -m "message"
to commit the changes to the repo.
- Again check the status of the git repo using the git status
command, Now we can see the file is tracked and saved.
- when you perform the commit command operation in git you must give your user email ID and username. To give the username and user email id following command was used.
git config --global user.email "user email id"
git config --global user.name "user name"
git init
touch <filename>
cat > <filename>
#Add some content to file
git add <filename>
git commit -m "new file added"
git status
Push the changes back to the repository on GitHub.
After completing the commit command operation, enter the git push
command in the terminal. so all the local repositories will be pushed to the Github web platform by following the command.
git push <remote-name> <branch-name>
Here remote name is 'origin' which represents the remote URL of the GitHub web platform.
git push origin main
For more understanding, you can refer to this video - Understanding Git
Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.
Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.
Happy Learning!
~kritika :)