Day 9 : Deep Dive into Git & GitHub

Day 9 : Deep Dive into Git & GitHub

What is Git and why is it important?

Git is a tool used for source code management. It is an open-source version control system for keeping track of changes to files. When a developer makes a change to a code file, they can commit that change to their local repository. Then, they can push their changes to a remote Git repository.

Git allows users to keep track of all the changes made to a file and revert to specific versions when needed.

The key objectives of Git are as follows:

  • Speed and efficiency

  • Data integrity

  • Support for distributed and non-linear workflows

What is the difference between the Main Branch and the Master Branch?

The master branch is a default branch in Git. The default branch of any GitHub repository uses main as the default branch name, which was earlier master.

Difference between Git and GitHub?

What is the difference between local & remote repositories? How to connect locally to remotely?

The local repository is a Git repository which is stored on your computer. Local repositories reside on the computers of team members.

The remote repository is usually used by teams as a central repository into which everyone pushes the changes from their local repository and from which everyone pulls changes to their local repository.

Tasks :

1.Create a repository named "Devops" on GitHub

Click on Create a new Repository and fille in the details.

2.Connect your local repository to the repository on GitHub

To connect the local repository to the remote repository on GitHub we first need to initialize a new Git repository on the local machine. Initializing the local repository can be done by using the command “git init”.

Add a file to the new local repository by using the command git add commit the file using the command git commit.

Add the remote repository of your GitHub repository to the local repository using the git remote add origin command.

git remote add origin <remote repository URL>

In the git Terminal, add the URL for the remote repository where the local repository will be pushed. Then create a token in GitHub by going to Settng -> Developer Setting -> Personal Access Tokens. This token needs to be configured in the local repository using the git remote set-url origin command so that while connecting to the remote repo we don't need to provide authentication every time.

git remote set-url origin github-token@<remote repository URL>

We can push the changes from your local repository to GitHub using the command git push origin master and to pull the changes from the remote repository we use the git pull origin master command.

So this is how we can connect our local repository to the remote repository on GitHub.