Deep Dive in Git & GitHub for DevOps Engineers.
1. What is Git, and why is it important?
Git is a distributed version control system. Distributed means that it has a remote repository which is stored on a server, and it has a local repository which is stored on the local computer of every developer working on the project.
Version control means we can go back in time and work with a different version of our code and change it without impacting the current version of the code. Git stores all versions of our code and allows us to work with branches.
Git is like a time machine for your code. It keeps a record of all changes made to your code, so if something goes wrong, you can go back to a previous version. It’s also like a team playground. Multiple people can work on different parts of the same project without stepping on each other’s toes. When they’re done, Git helps combine all the changes into one project. So, it’s important because it saves time, prevents confusion, and keeps our coding work organized.
2.What is the difference Between the Main Branch and the Master Branch?
When you create repository on local machine, you need to go inside it and execute "git init" command. After git init command repository gets initiated and .git folders gets created. Also one default branch gets created with default name "master".
When you create repository on GitHub using UI (website) then automatically git init command gets run in background and .git folder gets created. Also one default branch gets created with the default name "main"
The main difference is Git uses "master" as the default branch name and GitHub uses "main" as the default branch name.
3.Can you explain the difference between Git and GitHub?
In simple words, git is software that we install on our system to utilise the features and functions of Git like version control, branching etc and GitHub is the UI version of Git hosted on the server where we push the code to store it safely and securely.
We can create repository and inside it we can create file, write our code and commit it using the GitHub UI also but we do it locally and then push our code to remote repository to store it securely. If required we can share our code with teammates and work together on the same code by creating separate branches.
4.How do you create a new repository on GitHub?
Steps:-
Login to github.com
Click on your profile picture in the top right corner.
Click on Your repositories
Click on New in the top right corner.
-
Add **Repository name "**Devops" and description
-
Click on "Create repository"
5.What is difference between local & remote repository? How to connect local to remote?
In simple words, a local repository is a directory or a folder in our local system where we have our code or project present, along with all the .git tracking files. and a remote repository is a folder (project) on the GitHub server stored remotely. We can push our local changes to the remote repository to share and collaborate with others. Also, we can pull from the remote repository to keep our local repository up-to-date.
Difference between git clone and git remote add
git clone: This command is used when you want to create a copy of an existing repository on your local machine. It’s like downloading a project from a remote repository (like GitHub) to your computer. This cloned repository has its own history, files, and branches.
git remote add origin: This command is used when you have a local repository (a project on your computer) and you want to connect it to a remote repository. The word ‘origin’ is an alias that represents the URL of the remote repository. After running this command, ‘origin’ will refer to the remote repository. You can then push your changes from your local repository to the remote one using git push origin.
In simple terms, use git clone when you see a cool project online and want to have it on your computer. Use git remote add origin when you have done some cool work on your computer and want to share it online on a platform like GitHub.
Task-1:
- Set your username and email address, which will be associated with your commits.
git config --global user.email "yesican.vinayak@gmail.com"
git config --global user.name "vinayak"
Task-2:
- Create a repository named "Devops" on GitHub
- Connect your local repository to the repository on GitHub.
git remote add Devops https://github.com/yesicanvinayak/Devops
- Create a new file in Devops/Git/Day-02.txt & add some content to it
Push your local commits to the repository on GitHub
I hope you enjoy the blog post!
If you find the blog helpful, please do like it and share it with your friends. If you have any doubts or questions related to the topics covered in the blog, feel free to ask them in the comments section. I’ll be more than happy to help!