Basic Git & GitHub for DevOps Engineers

Basic Git & GitHub for DevOps Engineers

Β·

5 min read

Git

It is a distributed version control system designed to manage and track changes to code and other files over time. It was created by Linus Torvalds in 2005 and has become one of the most widely used version control systems in the world.

Git allows developers to work collaboratively on a project, enabling them to make changes to the codebase and track these changes over time. It tracks changes to files in a repository, creating a record of each change made, who made it, and when. This allows developers to revert to earlier versions of the codebase, collaborate on new features, and manage conflicts when multiple developers make changes to the same codebase.

Git also enables developers to work on multiple branches of a project, allowing them to experiment with new features or changes without affecting the main codebase. Branches can be merged together when changes are ready to be incorporated into the main codebase.

Github

GitHub is a web-based platform that provides hosting services for Git repositories. It allows developers to store and manage their code, track changes to their codebase over time, collaborate with others on code, and share their code with the wider development community.

GitHub provides a user-friendly interface for managing Git repositories, making it easy for developers to create new repositories, track changes, and collaborate with others. It offers features such as code review, issue tracking, pull requests, and branching, which make it easier for developers to work on code collaboratively and manage complex development workflows.

GitHub also provides social features, such as the ability to follow other developers and projects, to discover new projects and connect with other developers in the community. It is widely used by developers and organizations of all sizes, including large enterprises, startups, and open-source projects.

In addition to hosting Git repositories, GitHub also offers a variety of tools and services for developers, such as continuous integration and deployment, code scanning, and security analysis. It is a popular platform for open-source development, providing a central location for developers to contribute to and collaborate on open-source projects.

πŸ‘‰πŸ»To create a new repository on GitHub with the name "my repository," you can follow these steps:

  1. Log in to your GitHub account and click on the "+" icon in the top right corner of the page.

  2. Select "New repository" from the dropdown menu.

  3. In the "Repository name" field, type "my repository" (without the quotes).

  4. You can optionally add a description of the repository in the "Description" field.

  5. Choose whether you want the repository to be public or private. If you choose private, you will need to have a paid GitHub account.

  6. Check the box to initialize the repository with a README file.

  7. You can optionally add a .gitignore file and a license for your repository by selecting the appropriate options.

  8. Click the "Create repository" button.

Your new repository "my repository" is now created on GitHub. You can now start adding files and making changes to the repository. You can also share the repository with others by giving them the link to the repository or by adding collaborators to the repository.

πŸ‘‰πŸ»To clone "my repository" from GitHub to your local machine, you can follow these steps:

  1. Go to the GitHub website and navigate to "my repository."

  2. Click on the green "Code" button on the right-hand side of the page.

  3. Click on the "HTTPS" tab to view the repository's HTTPS URL.

  4. Copy the repository's HTTPS URL to your clipboard.

  5. Open a terminal or command prompt on your local machine.

  6. Navigate to the directory where you want to clone "my repository."

  7. Type the following command and replace <repository-url> with the HTTPS URL you copied in step 4:

     git clone <repository-url>
    
  8. Press Enter to execute the command.

  9. Git will now clone "my repository" to your local machine, creating a new directory with the same name as the repository.

Once the repository is cloned, you can make changes to the files in the repository, commit the changes, and push the changes back to the remote repository on GitHub.

πŸ‘‰πŸ»To push "my repository" from your local machine to the repository on GitHub, you can follow these steps:

  1. Open a terminal or command prompt on your local machine.

  2. Navigate to the directory where "my repository" is located using the "cd" command.

  3. Make any changes or modifications to the files in "my repository."

  4. Use the "git status" command to check which files have been modified, added, or deleted.

  5. Use the "git add" command to stage the changes you want to commit. For example, to stage all changes, you can use the command:

     git add .
    
  6. Use the "git commit" command to commit the changes with a message. For example, to commit with the message "Updated files":

     git commit -m "Updated files"
    
  7. Use the "git push" command to push the changes from your local machine to the repository on GitHub. For example:

     git push
    
  8. If this is the first time you are pushing changes to the repository, you will need to specify the remote repository and branch to push to using the command:

     git push -u origin main
    

    This will set the remote repository to the origin and the branch to main. After this, you can simply use the "git push" command to push changes to the same branch on the remote repository.

  9. Enter your GitHub username and password when prompted to authenticate the push.

Once the push is complete, the changes you made to "my repository" on your local machine will be reflected in the repository on GitHub.

#Git #DevOps #Github

Please free to write your thoughts and can connect with me on LinkedIn

Β