Day 9 Task: Deep Dive in Git & GitHub

Day 9 Task: Deep Dive in Git & GitHub

1. What is Git and why is it important?

Git is an open-source DevOps tool and also a distributed version control system. Git is used to track changes in the source codes, enable versioning and allow multiple developers to work together.

Before git developers used to keep their codes directly into the central server/repository without having copies of their own also there was a main problem with who made changes and when in the codes it was completely unknown to developers. But as Git is distributed version control in nature so many people can work concurrently on a single project. Every developer has a full copy of the repository, including the entire history of all changes. This makes it easier for developers to work together, as they don't have to constantly communicate with a central server to commit their changes or to see the changes made by others. Here, developers can do their work in offline mode too as they can keep a copy on their system, If the central repository goes down then there will be no chance of losing their data. 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”. Git is important because it tracks the changes and updates which is necessary while working on software development projects.

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

There is no particular difference between the two. main or master is the default branch when you create a repository. In GitHub when you create a branch by default it's set to main but you also can change it to master. Mainly GitHub changed the name from master to main as it sounds like a master-slave concept.

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

Git and GitHub are not the same things, Git mainly works on local systems and is used to track changes in codes and enable versioning. GitHub is a service used to store code that is remotely centralized and most Developers use this to store their code. GitHub is the largest host of source code in the world.

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

  • Create a new repository on GitHub by clicking on the "New" button on the GitHub homepage and filling out the repository details, such as the name, and description.

    Once the repository is created, copy the repository URL by clicking on the "Code" button and selecting the HTTPS or SSH URL.

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

A local repository is a copy of a project that resides on your local machine, while a remote repository is a copy of the same project that resides on a remote server, such as GitHub. The remote repository is usually used by teams as a central repository into which everyone pushes the changes from his local repository and from which everyone pulls changes to his local repository.

To connect locally to remote

1 . To initialize a local repo in the machine the command is git init and .git hidden folder will be created.

2. Add the files to your new local repository. This stages them for the first commit.

git add . and Commit the files that you've staged in your local repository by git commit -m "commit message"

3. Add the URL for the remote repository where your local repository will be pushed..

git remote add origin <url of central repos>

Verify that the remote was added successfully by running the git remote -v command.

git push origin master (or main )

4. Enter your username and Personal access token to push your codes to the central repo (GitHub)