title | datePublished | cuid | slug | cover |
---|---|---|---|---|
Basic Git & GitHub for DevOps Engineers #Day8 |
Thu Jul 27 2023 07:30:43 GMT+0000 (Coordinated Universal Time) |
clkku54dr000109md8tc42c61 |
basic-git-github-for-devops-engineers-day8 |
Welcome to Day 8 of the #90DaysOfDevOps challenge! Today, we’ll learn about GIT and GitHub. We often use these words interchangeably, but they both are not the same. In the fast-paced world of software development, collaboration, version control, and continuous integration are vital components of successful DevOps practices. Git and GitHub have emerged as essential tools in the DevOps engineer’s weapons, enabling teams to streamline workflows, improve code quality, and foster efficient collaboration. In this blog, we’ll explore the fundamentals of Git and GitHub, their significance in the DevOps ecosystem, and how they revolutionize the way development teams work together to deliver exceptional software.
Git is a distributed version control system that allows multiple developers to work together on the same project without stepping on each other’s toes. It gives you the superpower to manage and track changes to your code, making it easier to fix bugs, experiment with new features, and seamlessly roll back to previous versions if needed. No more living in fear of breaking the code! Git has your back!
GitHub is a web-based platform that provides hosting for version control using Git. It is a subsidiary of Microsoft, and it offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects.
Version control is a system that tracks changes to a file or set of files over time so that you can recall specific versions later. It allows you to revert files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more.
There are two main types of version control systems: centralized version control systems and distributed version control systems.
-
A centralized version control system (CVCS) uses a central server to store all the versions of a project’s files. Developers check out files from the central server, make changes, and then “check in” the updated files. Examples of CVCS include Subversion and Perforce.
-
A distributed version control system (DVCS) allows developers to clone an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.
-
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.
Overall, the decentralized nature of a DVCS allows for greater collaboration, flexibility, and security, making it a popular choice for many teams.
![](https://miro.medium.com/v2/resize:fit:875/0*VFqE5vzaDdBv5-e6.jpg align="left")
You can download it from the official website at
sudo apt-get update && sudo apt-get install git
git --version
You can signup from:
github.com
Command Description
git init Initializes a new Git repository in the current directory.
git clone Creates a local copy of a remote repository.
git add Adds changes or new files to the staging area for the next commit.
git commit Records changes to the repository with a commit message.
git status Shows the status of the working directory and staging area.
git push Uploads local commits to a remote repository.
git pull Fetches and merges changes from a remote repository.
git branch Lists, creates, or deletes branches in the repository.
git checkout Switches to a different branch or restores files from a commit.
git merge Combines changes from one branch into another branch.
git log Displays a history of commits in the repository.
git remote Manages remote repositories linked to the local repository.
step 1: Sign in to your GitHub account using your username and password.
step 2: Once you are signed in, click on the “+” icon in the top-right corner of the GitHub homepage. From the dropdown menu, select “New repository.” or, go to repositories and click on ‘new’ in the top right corner.
![](https://miro.medium.com/v2/resize:fit:875/1*4oc3eCX28EpMGnM4ebWEgQ.png align="left")
Step 3: Set up the repository: Now Add the repository name and other details like whether you want to keep it public(publically accessible) or private repo.
![](https://miro.medium.com/v2/resize:fit:875/1*vrl9pkyJbaPljk2OuXoEUA.png align="left")
Then click on ‘create repository’
you have successfully created a repository.
step 4: After creating the Repository it will look something like this :
![](https://miro.medium.com/v2/resize:fit:875/1*6Bo1LVM4hJ38TPN1KTiKuA.png align="left")
step1: click on <>code, after that, we can see a path, and copy that path
step 2: lets go into your local machine .
step 3: git clone <paste_the_copied_link_here>
it will clone your repository into your local.
![](https://miro.medium.com/v2/resize:fit:875/1*vgi_4_YA2lBdTUYzSC4jLQ.png align="left")
Create a few files or do the code you want to and then commit them.
![](https://miro.medium.com/v2/resize:fit:875/1*1GNsYj63uNiSAE6yTnR5VQ.png align="left")
We have create 2 files and added few line of code in each file.
We will now commit these changes but in order to commit we will add them to staging directory and then commit them.
![](https://miro.medium.com/v2/resize:fit:420/0*1Dov3X2OXrIa3zZ0.jpg align="left")
You can see in picture about is Git Working Tree.
In the below screenshot using git status
command you can track your code stage, and track them using git add
command. This is following command useful for committing code.
![](https://miro.medium.com/v2/resize:fit:875/1*pc5hoo0kWirfy4D9ycU2yg.png align="left")
![](https://miro.medium.com/v2/resize:fit:875/1*FM9JGWbCdaVWdZdswrJFHw.png align="left")
Remember we only committed in local repo not the remote repo(GitHub).
We need to push this code in order to commit code to remote repo.
git push origin <branch-name>
![](https://miro.medium.com/v2/resize:fit:875/1*xXJ2BsAbskmI_NhVNr-ngg.png align="left")
![](https://miro.medium.com/v2/resize:fit:875/1*Yjs9cQ38t752nJ61hlbaQw.png align="left")
Congratulations, dear reader! You’ve mastered the art of Git and GitHub, joining the ranks of legendary DevOps engineers! Embrace version control and collaboration, and your coding adventures shall know no bounds!
May your repositories be evergreen, and your codebase shine brightly among the stars! Happy coding!
Remember, the magical world of DevOps holds infinite wonders, so stay curious and keep learning!