Day 8 : Basic Git & Github

Day 8 : Basic Git & Github

What is Git ?

Git is a version control system. Git helps you keep track of code changes. Git is used to collaborate on code. This system allows you to track changes to files and coordinate work on those files among multiple people.

What is GitHub?

GitHub is a code hosting platform for collaboration and version control. GitHub lets you (and others) work together on projects. GitHub is a web-based platform that provides hosting for version control using Git. It is also used for hosting open-source projects.

What is version control and how many types of version controls are there?

Version control is a system that tracks the progress of code across the software development lifecycle and its multiple iterations – which maintains a record of every change complete with authorship, timestamp, and other details – and also aids in managing change.

It allows multiple people to collaborate on a project simultaneously without overwriting each other's work.

Types of Version Control Systems:

  • Local Version Control Systems

  • Centralized Version Control Systems

  • Distributed Version Control Systems

Local Version Control Systems: It is one of the simplest forms and has a database that keeps all the changes to files under revision control. RCS is one of the most common VCS tools. It keeps patch sets (differences between files) in a special format on disk. By adding up all the patches it can then re-create what any file looked like at any point in time.

Centralized Version Control Systems: Centralized version control systems contain just one repository globally and every user needs to commit to reflecting one’s changes in the repository. Others can see your changes by updating.

Examples of CVCS include Subversion and Perforce.

Distributed Version Control Systems: Distributed version control systems contain multiple repositories. Each user has their own repository and working copy. Just committing your changes will not give others access to your changes. This is because commit will reflect those changes in your local repository and you need to push them to make them visible on the central repository. Similarly, When you update, you do not get others’ changes unless you have first pulled those changes into your repository.

To make your changes visible to others, 4 things are required:

  • You commit

  • You push

  • They pull

  • They update

The most popular distributed version control systems are Git, Darcs and Mercurial.

Why do we use DVCS over CVCS?

There will be just one repository and that will contain all the history or version of the code and different branches of the code. So the basic workflow involved in the centralized source control is getting the latest version of the code from a central repository that will contain other people’s code as well, making your own changes in the code, and then committing or merging those changes into the central repository.

So everything is centralized in this model.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Tasks for some basic hands-on practice.

Task 1 - Create a new repository on GitHub and clone it to your local machine.

Step 1: Create a New Repository on GitHub

  1. Go to GitHub and log in to your account.

  2. Click on the '+' sign in the top-right corner and select "New repository".

  3. Give your repository a name, choose visibility (public or private), and a description.

  4. Optionally, choose to initialize the repository with a README file, a .gitignore file, or a license.

  5. Click "Create repository".

Step 2: Clone the Repository to Your Local Machine

Now that you have a repository on GitHub, you'll want to bring it to your local environment.

  1. Copy the URL of your newly created repository from the GitHub page.

  2. Open a terminal or command prompt on your local machine.

  3. Use the git clone <repository_url> command, replacing <repository_url> with the URL you copied.

COPY

git clone <repository_url>

Task 2 : Make some changes to a file in the repository and commit them to the repository using Git.

Make Changes and Commit Them

  1. Navigate to the directory where you cloned the repository.

  2. Create a new file or make changes to an existing one.

  3. Use the following Git commands to commit your changes:

git add .
git commit -m "Added/Modified file"

Push the Changes to GitHub

Once you've committed your changes locally, it's time to push them back to the GitHub repository.

git push origin main

This command pushes the changes from your local main branch to the remote repository on GitHub.

So now you can verfiy the changes by visiting your repository on GitHub in your browser. You will now see the file you added or modified. So in this way you can see how things work through using Git and GitHub for version control and collaborative development.

Thanks for reading my blog #day8 on git and github.
Do like and give your suggestions for correction.

#git #github #Devops

Stay connected :
Linkedin: https://www.linkedin.com/in/piyush-chauhan-a93989167/