Git & GitHub for DevOps Engineers | Part 2

Git & GitHub for DevOps Engineers | Part 2

·

5 min read

In my last blog, we discussed VCS, why we prefer DVCS over CVCS, an introduction to Git and GitHub, created a repository in GitHub, and pushed a file from our local repository to GitHub. You can read my blog here if you haven't already: Git & GitHub | Part 1.

Let us discuss those topics again and understand them in easy terms or Layman's terms.

What is Git? Why is Git important?

Git is a type of VCS, specifically Distributed VCS.

Git helps users to be precise developers to track their changes to the code, and collaborate with the team, manage multiple versions of code. Git is fast and efficient and capable to handle large repositories, complex branching, and merging workflows.

What is the difference Between Main Branch and Master Branch?

Mostly in Git, 'Main' and 'Master' branch terms are used interchangeably. The usage of these terms is purely cultural and convenient.

Some developers use 'main' as their default branch. While some use 'master' as their default branch.

While the functionality is the same, the default branch is the one where the stable code is stored.

Can you explain the difference between Git and GitHub?

Git is a Distributed VCS that allows developers to manage their codes and maintain the version. Whereas GitHub is a web-based service for Git repositories. There are many other platforms for hosting Git Repositories like GitLab, BitBucket, etc.

Git

GitHub

Git is a distributed version control system (VCS)

GitHub is a web-based  service for Git repositories

Git is a command-line tool

GitHub provides a user interface for working with Git repositories

Git allows developers to track changes to their code over time

GitHub provides a platform for storing, sharing, and collaborating on Git repositories

Git can be used independently or with other hosting services

GitHub is just one of several hosting services for Git repositories

Git is a free and open-source software

GitHub offers both free and enterprise plans for hosting repositories and accessing additional features

Git does not provide collaboration features such as pull requests or issue tracking

GitHub provides a range of collaboration tools such as pull requests, issue tracking, code reviews, and more

Git does not require an internet connection

GitHub requires an internet connection for hosting and accessing repositories

How do you create a new repository on GitHub?

To create a new repository in GitHub:

  1. Log in to your GitHub account. Go to the Home Page of your account.

  2. Click on the 'New' option, which is in a green color box.

  3. Type the Repository Name required.

  4. Give a Description of the repository, if you require it.

  5. You can select the repository to be either Public or Private.

  6. If you want to initialize this repository, Select the checkbox for 'Add a README file'.

  7. Click on 'Create Repository'.

Voila! The Repository is created.

What is the difference between local & remote repositories? How to connect the local repository to the remote repository?

A local Repository is a repository that is stored in the developer's computer or the local system. A remote repository is a repository that is stored on a remote server, typically on platforms like GitHub or BitBucket.

To connect the local repository to the remote repository:

  1. Create a remote repository 'MyRepo' on GitHub.

  2. In your local repository, add the URL of the remote repository 'MyRepo' as a new remote by using the command:

     git remote add <RepoName> <URL of the remote repository>
    
  3. You can push the changes that are in the local repository to the remote repository using the command:

git push -u <NameofRemoteRepo> <NameoftheBranch>

Tasks

Task 1: Set your user name and email address, which will be associated with your commits.

To set your user name and email address in Git, you can use the following commands:

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

To verify this, the following commands need to be run:

git config --global --list

Task 2: Create a repository named "Devops" on GitHub. Connect your local repository to the repository on GitHub. Create a new file in Devops/Git/Day-02.txt & add some content to it. Push your local commits to the repository on GitHub.

Create a repository named "Devops" on GitHub:

You can follow the steps mentioned in the previous part of the blog, and create a Repository named "Devops"

Connect your local repository to the repository on GitHub.

To connect your local repository to the repository on GitHub, copy the URL link of the repository and execute the following commands on your system:

git config --global init.defaultBranch main
git remote add Devops https://github.com/thesnehasuresh/Devops.git

The default branch needs to be set to 'main' as a good practice.

Create a new file in Devops/Git/Day-02.txt & add some content to it.

Create a New Directory Devops/Git and create a file named Day-02.txt. Add any content to it.

To create a new file, execute the following commands:

mkdir Devops/Git
cd Git
vim Day-02.txt
"This is my new File of day 9 challenge"

Voila! And it's done.

Push your local commits to the repository on GitHub.

To push the following to the repository on GitHub:

git add .
git commit -m "First Commit"
git push -u origin main

And it's done! This can be verified on the GitHub repository.


To help me improve my blog and correct my mistakes, I am available on LinkedIn as Sneha K S. Do reach me and I am open to suggestions and corrections.

#Day9 #90DaysofDevops

Did you find this article valuable?

Support Sneha K S by becoming a sponsor. Any amount is appreciated!