Day 9 of #90DaysOfDevOps

Day 9 of #90DaysOfDevOps

Why is Git important?

Git is a version control system. It maintains a history of all changes made to the code. The changes are stored in a special database called “repository”, also known as “repo”.

Two main advantages of using Git at software development:

  • Tracking the changes and updates. We are able to see who made which changes. Git also provides when and why a change was made.

  • Allowing to work collaboratively. Software development projects usually require many people to work together. Git provides the developers with a systematic way of doing that. Thus, the developers focus on the project instead of extensive communication sessions between the other developers.

What is difference Between Main Branch and Master Branch?

Main or Master is default branch when you create a repository. GitHub now use main as it's default branch while others still use master.

Before acquisition of GitHub by Microsoft, GitHub has master as their default branch, but some peoples at Microsoft thinks that master name kind of similar to slavery (master-slave) which is offensive according to Microsoft. Hence they changed its name to main.

Difference between Git and GitHub

S.No.GitGitHub
1.Git is a software.GitHub is a service.
2.Git is a command-line toolGitHub is a graphical user interface
3.Git is installed locally on the systemGitHub is hosted on the web
4.Git is maintained by linux.GitHub is maintained by Microsoft.
5.Git is focused on version control and code sharing.GitHub is focused on centralized source code hosting.
6.Git is a version control system to manage source code history.GitHub is a hosting service for Git repositories.
7.Git was first released in 2005.GitHub was launched in 2008.
8.Git has no user management feature.GitHub has a built-in user management feature.
9.Git is open-source licensed.GitHub includes a free-tier and pay-for-use tier.
10.Git has minimal external tool configuration.GitHub has an active marketplace for tool integration.
11.Git provides a Desktop interface named Git Gui.GitHub provides a Desktop interface named GitHub Desktop.
12.Git competes with CVS, Azure DevOps Server, Subversion, Mercurial, etc.GitHub competes with GitLab, Bit Bucket, AWS Code Commit, etc.

How do you create a new repository on GitHub?

  1. Create a Github account.

  2. Go to dashboard

  3. Click on New button.

  4. Type in a repository name and description of your repo.

  5. Choose whether you want your repo to be public repo or private

  6. Click the check box Add a README file

  7. You can .gitignore file of your choice based on the project.

  8. Click on create repository button.

What is difference between local & remote repository?

  • A local repository is hosted on a local machine for an individual user.

  • Remote repositories are hosted on a server that is accessible for all team members - most likely on the internet or on a local network.

Git Config

Git Config System

The Git config system level is the broadest configuration level and contains configuration information for your entire computer. Because Git config system configurations are specific to a computer’s operating system, most developers tend to keep the default configuration settings for this level.

To view a comprehensive list of your Git config system settings in the terminal, run:

git config --system --list

Git Config Global

Git config global configurations are applied to you as a user, stored in your home directory, and can overwrite Git config system settings. Unlike system configurations, developers regularly customize Git config global settings to fit their workflows. Some common Git config global configurations can be used to set your username, email address, default editor, commit message template, terminal colors, autocorrect, and more.

To view a comprehensive list of your Git config global settings in the terminal, run:

git config --global --list

git config --global user.name "Basavaraj" - Set global username

git config --global user.email "basuteli100@gmail.com" - Set global email

git config --global init.defaultBranch main - Git Config your Default Branch Name to Main

Git Config Local

The Git config local level includes settings that are Git repository specific and overwrite Git configurations on the global and system level. Developers frequently use Git config local commands to update the username and email associated with their work depending on what type of repository they’re working on.

git config --local --list

git config --local user.name "Basavaraj" - Set local username

git config --local user.email "basuteli100@gmail.com" - Set local email

You can view all of your Git config settings by running the show Git config command in the terminal:

git config --list --show-origin

The terminal will return your Git config settings in the same hierarchical order we covered previously, starting with the system level and narrowing to global and local.

  1. Create a directory and initialize it as a git repository

  2. git config --list --show-origin

  3. Git config global

  1. Git config local

Here, I have set username and email for a local repo called "git_repo" and is specific to that repo only. Let's try to understand this by creating a new repo.

But, the global variables we set earlier applies for all the local repositories in our machine. Also, git config --list --show-origin lists all the variables starting with the system level and narrowing to global and local. I have not set any system config, so we see global variables(username and email) and local variables.

How to connect local to remote?

  1. Create a repository in github

  2. Add remote repository to your local repository

  3. Create a directory named "Git" and a file in it and commit that directory

  4. Now, push the changes to remote repo.

    Push has failed as the local repo is not in sync with the remote repo

    Push has failed as the local repo is not in sync with the remote repo

    We need to pull the code from remote and rebase our local repo. Then push the contents of local repo to remote repo.

    Now, we can see the contents from local repo in our remote repo.