Git & GitHub for DevOps Engineers |Part 2
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?
Feature | Git | GitHub |
Type of tool | Version control system (VCS) | Web-based Git repository hosting service |
Functionality | Tracks changes in source code | Provides Git repository hosting and collaboration features, including pull requests, issues, and project management tools |
Local or cloud-based | Can be used locally on a computer | Cloud-based, accessible from anywhere with an internet connection |
Standalone vs. hosted | Standalone software that can be used with any Git repository | Hosts Git repositories and provides additional features for collaboration |
Pricing | Free and open source | Free for public repositories, paid plans for private repositories and additional features |
Popularity | Widely used by developers for version control and collaboration | One 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:
Log in to your GitHub account.
Click on the "+" icon in the top-right corner of the page and select "New repository" from the dropdown menu.
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.
Optionally, you can add a description for your repository to provide more details about your project.
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.
Select the checkbox to create a README file for your repository. This is a good practice as it provides an introduction to your project.
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:
Create a remote repository on GitHub.
Once you have created the remote repository, copy the URL of the repository.
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 isgit remote add [name] [remote repository URL]
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 isgit 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:
- Enter the following command, replacing
Your Name
with your actual name andyouremail@example.com
with your actual email address:
git config --global user.name "Your Name"
git config --global user.email youremail@example.com
- 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
Subscribe to my newsletter
Read articles from Prajwal Zalaki directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by