Day8: Devops Journey

Basic Git & GitHub:

What is git?

  • Git is a distributed version control system that is used for tracking changes made to a file or a set of files and allows multiple users to collaborate and work together on a file.

  • Mostly it is used by software developers to track the changes made in their codes, collaborating with multiple developers to make software better and controlling the version.

  • But it can be used by anyone in any field because it is set to track changes made to a given set of file.

Benefits:

  • Track changes made in a file: This includes a record of who made changes to what part of a file.

  • Revert any change: Suppose someone made an unsuitable change, with the help of git you can revert the changes to the previous version of that file.

  • Collaboration made easy: Git 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.

Git Repository Structure

It consists of 4 parts:

  1. Working directory: This is your local directory where you make the project (write code) and make changes to it.

  2. Staging Area (or index): this is an area where you first need to put your project before committing. This is used for code review by other team members.

  3. Local Repository: this is your local repository where you commit changes to the project before pushing them to the central repository on Github. This is what is provided by the distributed version control system. This corresponds to the .git folder in our directory.

  4. Central Repository: This is the main project on the central server, a copy of which is with every team member as a local repository.

What is GitHub?

  • GitHub is a web-based platform that provides hosting for distributed version control by Git. It provides all the functions of git such as distributed version control, source code management and few more features.

  • GitHub is simply Git on Web. Mostly it is used by developers as it made collaborating and version control easier with more user friendly features and it is also used for hosting open-source projects.

Version Control:

  • Version control is a system that tracks changes to a file or set of files over time. Its functionality includes comparing changes over time, bug fixes and recalling specific versions later.

  • It allows us to revert files back to their previous state, revert the entire project back to a previous state or version, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.

  • Suppose someone made a change to a Windows Software by Microsoft in its latest update and it started causing a problem. So the developers can revert the entire version to its previous state or previous version. This will fix the errors and later they can release new version. So this is how version control works.

    What Is Git | Explore A Distributed Version Control Tool | Edureka

    Types of Version Control:

    1. Centralized Version Control System (cvcs)

    2. Distributed Version Control System (dvcs)

  • DVCS vs CVCS

    Here are the major differences between Distributed version control and Centralized Version control :

    | Distributed Version Control (DVCS) | Centralized Version Control (CVCS) | | --- | --- | | Each user has a complete copy of the repo. | Users check out a working copy from the central repo. | | No heavy reliance on network connectivity. | Requires network connection for most operations. | | Users can work offline with a local copy. | Offline work is limited, as constant connection to the central repo is needed. | | Each local copy serves as a complete backup. | Central repo is the single point of backup. | | Faster and more flexible branching and merging. | Branching and merging may be slower and less flexible. | | Enables parallel development with ease. | Parallel development may face more challenges. | | Git, Mercurial, Bazaar | CVS, SVN |

    Overall, the decentralised nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.

Task1: Install Git on your computer (if it is not already installed) & GIT basic commands:

#sudo apt-get install git

#sudo apt-get update

#git --version

Initialize a new Git repository:

#git init

start a new Git repository in the selected directory

Create two files, add them to staging:

  • Utilize the vim command to create files

  • Currently files are untracked

  • Use the git add command to add the newly created files to the staging area, preparing them for the next commit.

    This command stages the changes made to the specified files, marking them for inclusion in the next commit.

    Command used to add all files: git add .

  • You can check file status using git status command.

    Commit the changes:

    • Execute the git commit command to permanently save the changes made to the files along with a descriptive commit message.

      syntax: git commit -m "commit message"

    • Here, the -m flag allows you to include a commit message directly in the command. This message should succinctly describe the changes made in this commit.

      To check git history:

      • git log displays a chronological history of commits in a Git repository, showing commit messages, authors, dates, and unique identifiers.

        Task2:

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

          1. Make some changes to a file in the repository and commit them to the repository using Git

          2. Push the changes back to the repository on GitHub.

Solution:

Open https://github.com/ in chrome and create account.

Create a repository on GitHub

Click the + sign at the top right corner to create a new repository. Repositories are like your code folders online.

Name your repository and give it a description (this is optional).

Click the "Create repository" button to create the repository.

You will be prompted to this page:

Cloning the repo :

Copy the HTTPS and use git clone command followed by the https address to clone the repo in your local repository.

#git clone https://github.com/viveksinghcs165/Devops-journey.git

Create one new file on github:

#git pull origin main

#ls & new created file appears.

Similarly create one new file on local machine

On local machine new file is appear but not on git hub.

#git push origin main

Here it is asking for credentials. so we will create token on github and give access to others.

Github > profiles > settings > Developer settings > personal access tokens > classic token > generate a personal token > set expiry date > select scopes > create token > copy & paste on notepad for later use.

#git remote -v

#git remote set-url origin tokenurl@git repo path

It is changed now.

#git push origin main

This time it will not ask for username & password.

Now, go to github > my repositories

Now we can see from-local.txt by local user ubuntu.

  • Thank you for reading my blog:)