Table of contents
- #Day 8 Task
- What is Git?
- What is GitHub?
- What is Version Control? How many types of version controls do we have?
- Why do we use distributed version control over centralized version control?
- Install Git on your computer
- Create a free account on GitHub
- Create a new repository on GitHub and clone it to your local machine
- To clone the repository to your local machine, follow these steps:
- Make some changes to a file in the repository and commit them to the repository using Git
- ubuntu@ip-172-35-25-272:~$ cd devops-batch-3/
- ubuntu@ip-172-35-25-272:~/devops-batch-3$ ls README.md command.txt
- ubuntu@ip-172-35-25-272:~/devops-batch-3$ touch newfile
- ubuntu@ip-172-35-25-272:~/devops-batch-3$ vim newfile
#Day 8 Task
What is Git?
Git is a version control system that allows you to track changes to files and coordinate work on those files among multiple people. It is commonly used for software development but can be used to track changes to any set of files.
With Git, you can keep a record of who made changes to what part of a file, and you can revert to earlier versions of the file if needed. Git also makes it easy to collaborate with others, as you can share changes and merge the changes made by different people into a single version of a file.
What is GitHub?
GitHub is a web-based platform that provides hosting for version control using Git. It is a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its features. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects.
What is Version Control? How many types of version controls do we have?
Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
There are two main types of version control systems: centralized version control systems and distributed version control systems.
A centralized version control system (CVCS) uses a central server to store all the versions of a project's files. Developers "check out" files from the central server, make changes, and then "check-in" the updated files. Examples of CVCS include Subversion and Perforce.
A distributed version control system (DVCS) allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and later merge their changes into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.
Why do we use distributed version control over centralized version control?
Better collaboration: In a DVCS, every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don't have to constantly communicate with a central server to commit their changes or to see the changes made by others.
Improved speed: Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don't have to communicate with a central server.
Greater flexibility: With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.
Enhanced security: In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.
Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.
Install Git on your computer
You can download it from the official website at
sudo apt-get update && sudo apt-get install git
git --version
output
git version 2.34.1
Create a free account on GitHub
You can signup from:
https://github.com/
Create a new repository on GitHub and clone it to your local machine
let's see step by step
Go to github.com and log in to your account.
Click the “New Repository” button.
Enter a name for your repository and a brief description.
Choose whether you want the repository to be public or private.
Choose repository visibility. Click on the public if you want your repository to be cloned by anyone.
Click the “Create repository” button.
To clone the repository to your local machine, follow these steps:
On the repository page on GitHub, click the “Clone or download” button.
Click the “Copy to clipboard” icon to copy the clone URL.
Open a terminal window and navigate to the directory where you want to clone the repository.
git clone
https://github.com/Arijit094/devops-batch-3.git
output :
Cloning into 'devops-batch-3'... remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (6/6), done.
ls
output :
devops-batch-3
Make some changes to a file in the repository and commit them to the repository using Git
ubuntu@ip-172-35-25-272:~$ cd devops-batch-3/
ubuntu@ip-172-35-25-272:~/devops-batch-3$ ls
README.md
command.txt
ubuntu@ip-172-35-25-272:~/devops-batch-3$ touch newfile
ubuntu@ip-172-35-25-272:~/devops-batch-3$ vim newfile
ubuntu@ip-172-35-25-272:~/devops-batch-3$ git status
output :
On branch main, Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add ..." to include what will be committed)
newfile
nothing added to the commit but untracked files are present (use "git add" to track)
ubuntu@ip-172-35-25-272:~/devops-batch-3$ git add newfile
ubuntu@ip-172-35-25-272:~/devops-batch-3$ git status
output :
On branch main, Your branch is up to date with 'origin/main'.
Changes to be committed: (use "git restore --staged ..." to unstage)
new file:
newfile.txt
Now it's time to commit
ubuntu@ip-172-35-25-272:~/devops-batch-3$git commit -m "new commit from Singapore"
successfully committed check the git log
ubuntu@ip-172-35-25-272:~/devops-batch-3$ git log
commit
c254ad8e25460e348b5fdd02e9d382c850950077
(HEAD -> main) Author: Ubuntu ubuntu@ip-172-35-25-272.ap-southeast-1.compute.internal Date: Thu Apr 13 12:14:56 2023 +0000new commit from Singapore
git push origin master
using this command you can successfully push yournewfile
on the GitHub repository
Thank you very much for giving your valuable time for reading this article !!☺😊
Arijit Manna