Git & GitHub for DevOps Engineers |Part 2

Prajwal ZalakiPrajwal Zalaki
5 min read

Why Git is important?

Git is important because it enables developers to work collaboratively on the same codebase while keeping track of changes and maintaining a history of all modifications made to the code. It also enables developers to easily branch the code, which allows for the creation of new features or experiments without affecting the main codebase. Git also allows for easy merging of these branches, making it easier to integrate changes from different sources.

What is the difference Between Main Branch and Master Branch?

The terms "main branch" and "master branch" are often used interchangeably to refer to the primary branch in a Git repository.

In terms of functionality, the main branch and master branch are exactly the same. They both represent the default branch in a repository and can be used for version control and collaboration.

Can you explain the difference between Git and GitHub?

FeatureGitGitHub
Type of toolVersion control system (VCS)Web-based Git repository hosting service
FunctionalityTracks changes in source codeProvides Git repository hosting and collaboration features, including pull requests, issues, and project management tools
Local or cloud-basedCan be used locally on a computerCloud-based, accessible from anywhere with an internet connection
Standalone vs. hostedStandalone software that can be used with any Git repositoryHosts Git repositories and provides additional features for collaboration
PricingFree and open sourceFree for public repositories, paid plans for private repositories and additional features
PopularityWidely used by developers for version control and collaborationOne of the most popular Git repository hosting services, used by millions of developers

In summary, Git is a standalone version control system that tracks changes in source code, while GitHub is a web-based Git repository hosting service that provides additional collaboration features. While Git can be used locally on a computer, GitHub is cloud-based and accessible from anywhere with an internet connection.

How do you create a new repository on GitHub?

To create a new repository on GitHub, follow these steps:

  1. Log in to your GitHub account.

  2. Click on the "+" icon in the top-right corner of the page and select "New repository" from the dropdown menu.

  3. On the "Create a new repository" page, enter a name for your repository. This should be a short, descriptive name that identifies the purpose of your project.

  4. Optionally, you can add a description for your repository to provide more details about your project.

  5. Choose whether you want your repository to be public or private. Public repositories are visible to everyone, while private repositories can only be accessed by authorized collaborators.

  6. Select the checkbox to create a README file for your repository. This is a good practice as it provides an introduction to your project.

  7. Click on the "Create repository" button to create your new repository.

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

A local repository is a copy of a Git repository that is stored on your local computer, while a remote repository is a copy of the same repository that is stored on a server or another remote location. The primary difference between a local and a remote repository is that the local repository is used for local development and the remote repository is used for collaboration and sharing changes with others.

To connect a local repository to a remote repository, you'll need to perform the following steps:

  1. Create a remote repository on GitHub.

  2. Once you have created the remote repository, copy the URL of the repository.

  3. Add the remote repository to your local repository: In your local repository, use the git remote add command to add the remote repository. The syntax for this command is

    git remote add [name] [remote repository URL]

  4. Push changes to the remote repository: Once you've added the remote repository to your local repository, you can push your changes to the remote repository using the git push command. The syntax for this command is

    git push [remote name] [branch name]

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 git config command with the --global flag to set the configuration globally for all Git repositories on your computer. Here's how to do it:

  1. Enter the following command, replacing Your Name with your actual name and youremail@example.com with your actual email address:
git config --global user.name "Your Name"
git config --global user.email youremail@example.com

  1. You can verify that your user name and email address have been set by using the using below command
git config --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

Connect your local repository to the repository on GitHub.

Use the git remote add command to set the remote URL for your local Git repository. The syntax for this command is

git remote add devops https://github.com/prajwalzalaki/devops.git

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

Push your local commits to the repository on GitHub

To push local commits to repository use the below command:

git add .
git commit -m "comments"
git push <remote> <branch>

Thanks for reading

~Prajwal

0
Subscribe to my newsletter

Read articles from Prajwal Zalaki directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prajwal Zalaki
Prajwal Zalaki