Day 9: Deep Dive in Git & GitHub for DevOps Engineers.

Day 9: Deep Dive in Git & GitHub for DevOps Engineers.

Find the answers by your understanding .......

1. What is Git and why is it important?

Git is a version control system. It is a way of tracking changes to files over time. This is useful for software development, as it allows developers to go back to previous versions of the code if they need to. Git is also used for other purposes, such as managing documentation and tracking changes to websites.

Git is important because it allows developers to work together more efficiently. It also helps to prevent errors and inconsistencies in code.

2. What is the difference Between the Main Branch and Master Branch??

The main branch and the master branch are two terms that are often used interchangeably in Git. However, there is a subtle difference between the two.

The main branch is the default branch in a Git repository. It is the branch that is used to track the latest changes to the code. The master branch is a special branch that is often used to represent the production version of the code.

In most cases, the main branch and the master branch are the same. However, there are some cases where they may be different. For example, if you are working on a new feature, you might create a new branch and then merge it back into the main branch when the feature is complete.

3. Can you explain the difference between Git and GitHub?

Git and GitHub are two different things. Git is a version control system, while GitHub is a hosting service for Git repositories.

Git is the software that you use to track changes to your files. GitHub is a website that allows you to store your Git repositories and collaborate with other developers.

You can use Git without GitHub, but GitHub makes it easier to manage your Git repositories and collaborate with other developers.

4. How do you create a new repository on GitHub?

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

  1. Go to the GitHub website: https://github.com/.

  2. Sign in to your GitHub account or create a new account if you don't have one.

  3. Click the "New Repository" button.

  4. In the "Repository name" field, enter the name of your new repository.

  5. (Optional) In the "Description" field, enter a description of your repository.

  6. (Optional) Select the visibility of your repository.

  7. Click the "Create repository" button.

5. 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 computer. A remote repository is a copy of a Git repository that is stored on a server.

The main difference between local and remote repositories is that local repositories are stored on your computer, while remote repositories are stored on a server. This means that you can access your local repositories even if you are not connected to the internet, but you need to be connected to the internet to access your remote repositories.

To connect a local repository to a remote repository, you can use the git remote add command. The syntax for the git remote add command is:

git remote add <remote_name> <url>

Replace <remote_name> with the name of the remote repository and <url> with the URL of the remote repository.

For example, if you want to connect a local repository called my-project to a remote repository called origin that is hosted on GitHub, you would run the following command:

git remote add origin https://github.com/<your_username>/my-project.git

Once you have connected a local repository to a remote repository, you can push changes from your local repository to the remote repository and pull changes from the remote repository to your local repository.

Tasks

task-1:

  • Set your user name and email address, which will be associated with your commits.

To set my user name and email address, I can use the following Git commands:

The git config command is used to set Git configuration options. The --global flag tells Git to set the option for all repositories.

The user.name option specifies the user name that will be associated with my commits. The user.email option specifies the email address that will be associated with my commits.

Once I have set my user name and email address, I can check to make sure that they are set correctly by running the following command:

git config --list

The output of the command should include the following lines:

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

Here are the steps on how to 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 and add some content to it, and push your local commits to the repository on GitHub:

  1. Go to the GitHub website: https://github.com/.

  2. Sign in to your GitHub account or create a new account if you don't have one.

  3. Click the "New Repository" button.

  4. In the "Repository name" field, enter the name of your new repository, which is "Devops".

  5. (Optional) In the "Description" field, enter a description of your repository.

  6. (Optional) Select the visibility of your repository.

  7. Click the "Create repository" button.

Once you have created the repository on GitHub, you can connect your local repository to it. To do this, you need to know the SSH URL of the remote repository. You can find the SSH URL by clicking the "Clone or download" button on the repository page and then clicking the "SSH" button.

Once you have the SSH URL, you can connect your local repository to the remote repository using the following Git command:

git remote add origin <ssh_url>

Replace <ssh_url> with the SSH URL of the remote repository.

Now that you have connected your local repository to the remote repository, you can create a new file in the Devops/Git/Day-02.txt directory and add some content to it. To do this, you can use the following Git commands:

cd Devops/Git
touch Day-02.txt
echo "This is the content of Day-02.txt" >> Day-02.txt

The first command changes the current working directory to the Devops/Git directory. The second command creates a new file called Day-02.txt. The third command adds the content "This is the content of Day-02.txt" to the Day-02.txt file.

Once you have added content to the Day-02.txt file, you can commit the changes to your local repository using the following Git command:

git add Day-02.txt
git commit -m "Add Day-02.txt file"

The first command adds the Day-02.txt file to the staging area. The second command commits the changes to the local repository.

Finally, you can push the changes from your local repository to the remote repository using the following Git command:

git push origin master

The origin is the name of the remote repository and master is the name of the branch.

Let me know if you have any other queries.

Thank You

If you liked this blog then click on ❤

and do follow for more interesting and helpful blogs.

Did you find this article valuable?

Support GCP by becoming a sponsor. Any amount is appreciated!