Day 9  Deep Dive in Git and Github for Devops Engineers

Day 9 Deep Dive in Git and Github for Devops Engineers

Β·

4 min read

  1. What is Git and why is it important?

    Git is a version control system, that allows any software developer, or development project to track changes made in files and coordinate work of those files among multiple people.
    With the help of GIT, we can keep
    πŸ”„
    Version Control*: Keep a history of changes and who made the changes
    🀝* Collaboration*: Work with others seamlessly, we can rever to previous
    changes, if required
    🧹* Branching*: Easily create and manage branches. This is mostly used when
    work is divided into teams and everyone is working on different features
    and once done, everyone can merge the feature and create one single
    project.
    🌐* Remote Repositories*: Share code across the web. Because of this feature of
    git, so many open-source projects can work and people all around the globe
    can contribute.
    πŸ“¦* Modularity*: Split code into manageable pieces, due to which it's now easy to
    find bugs and make changes in a local repo, test it in the test system before
    merging and deploying the code in prod.
    πŸ—οΈ* Merging*: Combine code changes effortlessly, this goes with branching as
    once a feature is enhanced or created, we first create a separate branch and
    later on Merge it .*

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

    πŸ› οΈ There is no such difference between the Main and Master branches in Git. The master branch has been central to various development workflows, serving as the main point of reference for stable code. Despite the widespread usage of the master branch, the software development community has recognized the need for a more inclusive default branch name, leading to the introduction of the "main" branch to replace the master branch in Git repositories.

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

    Git vs. GitHub

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

    πŸ§‘β€πŸ’Ό Before creating a new repository in Github, you must have an account in
    Github, and this account creation is as easy as creating your social media
    accounts like Facebook or Instagram. And the best part is you can use your

    gmail account to sign up your GitHub account

    Below are the steps to Create a Repository in GitHub

    There are 2 places from where you can create a repository

    This is available on Left panel

    This is available beside your profile icon on Top right side of your GitHub account.

    Once you Press New Repository, you go to another page to Create a Repository

    Once You give a name to your repository and Define its visibility, public or private, you can press β€œcreate repository” on the bottom corner of the page.

    πŸŒŸπŸŽ‰ Tada you have created your first repository

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

    🎈 A remote repository is hosted on a remote (this could be on the internet or an off-site server; it could even be the same machine in a different path) and is shared among multiple team members. A local repository is hosted on a local machine for an individual user.

    In the above example, we have created a repository and now we want to

    connect local to remote repository.

    1. Add this as a remote for your local repository by running the following commands in your terminal

2 Now add something in this repository, we have added a file "newfile2.txt"

3 Now after adding a new file in git we must commit it so that this should be saved

However, you must have seen that while we try to commit, it is through an error asking us to provide a user.email and user.name. These are the details that are used to know who is committing the changes to git. Basically, this Set your user name and email address, which will be associated with your commits.

That can be checked using git command git log

4 Now these changes are only saved and committed locally on the desktop on, this has to be pushed in your actual GitHub repository

πŸ”‘ In the screenshot, you will notice that I am being prompted to add my username and password. To avoid this you will need to authenticate to GitHub as follows.

πŸ”‘ Create a token in your GitHub: click on your pic in the top right-hand corner of the GitHub β†’ settings β†’ developer settings β†’ personal access tokens β†’ token classic β†’ generate a new token generate token new (classic) β†’ Copy this code and paste it in notepad.

πŸ”‘ Next run this command with the token included, in your terminal:

$ git remote set-url origin https://<add your token here>@github.com/S47sawan/devops.git

πŸ”‘ Or else you can also paste the same code generated in the above step while prompting for a password when you run git push command, in either case, you will be able to push the changes from the local repo to the central repo with any password authentication or prompts for a password

Β