DEV Community

Asad
Asad

Posted on • Originally published at blog.automation-dev.us on

Basic Git & GitHub for DevOps Engineers

What is Git?

Git is a popular and widely used version control system that allows developers to keep track of changes made to their code over time, collaborate with others, and work on multiple versions of their code.

What is a GitHub?

GitHub is a web-based platform that provides hosting for Git repositories and offers additional features such as issue tracking, pull requests, and code reviews. It allows developers to share and collaborate on their code with others.

What is Version control?

Version control is a system that allows developers to keep track of changes made to their code over time, and enables them to revert to previous versions or collaborate with others on the same codebase.

Types of Version Controls

There are two main types of version control systems: centralized and distributed.

  • Centralized version control systems store code in a central server, while distributed version control systems create multiple copies of the repository on different computers.

  • Distributed version control offers several advantages over centralized version control, such as the ability to work offline and make commits locally, easier collaboration and branching, and a faster workflow.

Everything Combined

Git is a version control system that allows developers to keep track of changes made to their code, GitHub is a platform that provides hosting for Git repositories and additional features, version control is a system that allows developers to manage and track changes made to their code over time, there are two main types of version control systems (centralized and distributed), and distributed version control offers several advantages over centralized version control.

10 Basic git Commands

  1. git init: Initializes a new Git repository in your current working directory.

  2. git add: Adds changes made to your code to the staging area, which prepares them to be committed.

  3. git commit: Commits changes to the repository and creates a new snapshot of the code.

  4. git status: Shows the current status of the repository, including which files have been modified or added, and which files are ready to be committed.

  5. git log: Shows a history of all the commits made to the repository, along with their messages and other details.

  6. git branch: Lists all the branches in the repository, and shows which branch you are currently on.

  7. git checkout: Switches to a different branch or a specific commit.

  8. git pull: Updates the local repository with changes made in the remote repository.

  9. git push: Sends changes made locally to the remote repository.

  10. git clone: Creates a copy of a remote repository on your local machine.

Git has many more powerful features and commands that can help you manage your code and collaborate with others.

Task 1: New Repository in Github and Cloning it locally.

A GitHub account already exists. I created the repository Day-8-task on git. I will clone the repo and make changes to the README.md file and commit the changes to GitHub.

  • To clone the repository git clone followed by the repository link

git clone https://github.com/Arafique458/Day-8-Task.git

  • To configure the credentials, I will be using a Secret Access token to connect to the repository.

git config --global user.name "arafique458"

git config --global user.email "arafique458@gmail.com

  • To access the cloned directory

cd Day-8-task

  • To make changes to the README.md file

vim README.md

  • After making changes check the status of the file modified.

  • To stage, the changes git add . (this will stage all the files in the directory or we can specify the file want to stage)

  • To push the changes to the main repository in the GitHub git push origin main (I was prompted to enter credentials, I used the email address of the git hub and Access token)

Task 2: File in the repository changed and commit was made in the repository using Git

GitHub repository before making a commit

GitHub repository before making a commit

Task 3: Pushed Changed / Commit Screenshot of GitHub repository

Top comments (0)