Table of contents
- 🔶 What is Git?
- 🔴 Importance of Git
- 🔴 What is Git Repository?
- 🔶 What is the difference Between Main Branch and Master Branch?
- 🔶Can you explain the difference between Git and GitHub
- 🔶 Set your user name and email address, which will be associated with your commits.
- 🔹 Setting your commit email address in Git
- 🔹 Task: Create a repository named "Devops" on GitHub
- 🔹 Task: Connect your local repository to the repository on GitHub.
- 🔹 Task: Create a new file in Devops/Day-02.txt & add some content to it.
- 🔹 Task: Push your local commits to the repository on GitHub
- 🎉 Task Done👍 Day 09 of #90daysofdevops 💯
🔶 What is Git?
Git was also created by Linus Torvalds in the process of developing Linux. Git is a distributed version control system (VCS). 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 a source code versioning system that lets you track changes locally by creating a local repository that can be accessed only by the specific user, thereby allowing you to make changes to your local repository. The local repository is nothing but a clone of the central repository.
Git is a free and open-source distributed version control system (VCS) designed to handle everything from small to very large projects with speed and efficiency.
GIT, which stands for Global Information Tracker, is a powerful and widely-used version control system commonly used for software development and other collaborative projects.
🔴 Importance of Git
Better collaboration: In a DVCS, 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.
Improved speed: Because developers have a local copy of the repository, they can commit their changes and perform other version control actions faster, as they don't have to communicate with a central server.
Greater flexibility: With a DVCS, developers can work offline and commit their changes later when they do have an internet connection. They can also choose to share their changes with only a subset of the team, rather than pushing all of their changes to a central server.
Enhanced security: In a DVCS, the repository history is stored on multiple servers and computers, which makes it more resistant to data loss. If the central server in a CVCS goes down or the repository becomes corrupted, it can be difficult to recover the lost data.
🔴 What is Git Repository?
After you install Git, you can initialize it onto a project to create a new Git repo.
A Git repository is the
.git/
folder inside a project. This repository tracks all changes made to files in your project, building history over time. Meaning, if you delete the.git/
folder, then you delete your project’s history.For example, if we have created a folder in the c drive "Devops_demo"
Now, it is an empty folder.
The next step initialization is done with the help of the
git init
commandgit init //git initialization
🔶 What is the difference Between Main Branch and Master Branch?
The main branch is the default branch in a repository. It is usually used for the official development version of a project, where all the most recent changes are stored. The master branch, on the other hand, is the stable version of a project.
This branch is usually only updated with bug fixes and small enhancements to stabilize the code. The main branch is usually used for active development, while the master branch is the version that is used for production or deployment.
🔶Can you explain the difference between Git and GitHub
🔶 Set your user name and email address, which will be associated with your commits.
GitHub uses your commit email address to associate commits with your account on GitHub.com. You can choose the email address that will be associated with the commits you push from the command line as well as the web-based Git operations you make.
For web-based Git operations, you can set your commit email address on GitHub.com. You can set your commit email address in Git for commits you push from the command line.
Any commits you made before changing your commit email address are still associated with your previous email address.
🔹 Setting your commit email address in Git
You can use the git config
command to change the email address you associate with your Git commits. The new email address you set will be visible in any future commits you push to GitHub.com from the command line. Any commits you made before changing your commit email address are still associated with your previous email address.
1️⃣ Open Git Bash.
2️⃣ Set an email address in Git.
$ git config --global user.email "YOUR_EMAIL"
3️⃣ Confirm that you have set the email address correctly in Git
$ git config --global user.email
🔹 Task: Create a repository named "Devops" on GitHub
To create a new repository in GitHub, follow these steps:
Log in to your GitHub account and click the "+" sign in the upper right-hand corner of the dashboard.
Select "New repository" from the dropdown menu.
Choose a name for your repository.
For example, now we will create a repository name "Devops"
Optionally, add a description for your repository.
In the description box "Devops Data"
Choose whether you want your repository to be public or private. Public repositories are visible to everyone, while private repositories require authentication to access.
Select whether you want to initialize your repository with a README file, which is a good practice to give an overview of your project.
Choose a license for your repository if you wish to make it available for reuse by others.
Click the "Create repository" button.
Finally, we have created a "Devops" repository.
🔹 Task: Connect your local repository to the repository on GitHub.
When GitHub creates your repository, it presents an HTTP link, which is required as part of the git remote add origin command. The URL provided that uniquely identifies the GitHub repository I created is:
1️⃣ First, open your Github and select the repository name. Click on "<>code"
button dropdown list.
2️⃣ Select the HTTPS URL and copy that URL.
3️⃣ In local git, use the command
git remote add origin <URL>
This command will execute, but the system won't provide any feedback to the terminal window. To verify that the remote repo was added to your configuration, use the
git remote –v
command. This command will show that GitHub is the fetch and push target of the local repository.🔹 Task: Create a new file in Devops/Day-02.txt & add some content to it.
1️⃣ Go to Gitbash.
2️⃣ This is the most standard command to quickly create an empty text file. The command is quite simple to type and makes it quite easier to create several text files at once. The commands are as follows:
touch day02.txt
As simple as that, just type the word touch followed by the name of the file you like to give it, and done! you have created an empty text file inside of a terminal.
3️⃣ If you want to heavily edit a text file, you can use command-line text editors such as Vim, nano, and there are other options as well. We are using
vim day02.txt
press Enter.vim day02.txt
Now edit
vim day02.txt
file and add a new line in the file. with the help of the vim editor.vim editor will open and press the
Esc
button -->pressi
for insert Mode--> modify file --> pressEsc
then:wq!
and pressEnter
You can check the content with the help of the
cat
command.4️⃣ Here, we are now checking "user name" and "user email" with the following command.
git config user.name
git config user.email
5️⃣ The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. This will add all changes that are made to the local repository.
git add . or git add day02.txt
6️⃣ The git status command displays the state of the working directory and the staging area.
git status
7️⃣ Since we have finished our work, we are ready to move from stage
to commit
for our repo.
Adding commits keeps track of our progress and changes as we work. Git considers each commit
change point or "save point". It is a point in the project you can go back to if you find a bug, or want to make a change.
When we commit
, we should always include a message.
By adding clear messages to each commit
, it is easy for yourself (and others) to see what has changed and when.
git commit -m "first commit"
8️⃣ With the help of the git status
command. It allows us to see the tracked, untracked files and changes.
git status
🔹 Task: Push your local commits to the repository on GitHub
As you commit changes to your project locally, you can push those changes to GitHub so that others may access them from the remote repository.
we have successfully set up a remote repository with GitHub, and I successfully pushed our first commit to it with:
git push -u origin master
🎉 Task Done👍 Day 09 of #90daysofdevops 💯
In this article, we have covered the Day 09 task and learned about Git and its importance. Difference between Git and GitHub & created a new repository. We have learned also how to connect the local repository to the GitHub repository.
If you enjoyed this article please like it and share it with your friends and colleagues!
Thank you for reading🤓