Git & GitHub: A Deep Dive Guide for DevOps Engineers

Subho DeySubho Dey
5 min read

What is the difference between local & remote repositories?

A local repository and a remote repository are two concepts used in version control systems, such as Git, which allow developers to manage and collaborate on code changes. Here's the difference between the two:

  1. Local repository: A local repository is a copy of a codebase that is stored on your local machine. It contains all the files, folders, and commit history of a project, and you can make changes to the code, create new branches, and commit changes to the local repository.

How to Add a Salesforce DX Project to Source Control -step by step guide –  sfdc techie – Pavan's blog

  1. Remote repository: A remote repository is a copy of the codebase that is stored on a remote server, such as GitHub, GitLab, or Bitbucket. It serves as a central repository where multiple developers can collaborate on the same codebase. Changes made to the local repository need to be pushed to the remote repository to make them visible to other collaborators.

To connect a local repository to a remote repository and connect the local repository to the repository on GitHub.you can follow these general steps:

  • Create a repository named "Devops" on GitHub

Once you have a GitHub account, log in to your account. From the main dashboard, click on the "New" button in the top right corner to create a new repository.

Step 1: In the "Repository name" field, enter "DevOps". You can also provide an optional description for your repository. You can choose to make the repository public or private, depending on your requirements. If you want to initialize the repository with a README file, select the checkbox. You can also choose to add a license and/or a .gitignore file, based on your project's needs.

Step 2: Click on "Create repository" After filling in the required information, click on the "Create repository" button to create your new "DevOps" repository on GitHub.

Step 3: Set Up Your Local Repository Once your repository is created on GitHub, you can set up your local repository to connect with it. You can use a command-line interface (CLI) or a graphical user interface (GUI) tool that supports Git.

If you're using a CLI, navigate to the directory on your local machine where you want to create your local repository. Run the following commands:

git init               # Initializes a new Git repository
git remote add origin <repository-url>   # Connects your local repository to the remote repository on GitHub

Replace <repository-url> with the URL of your "DevOps" repository on GitHub.

Step 4: Once the local and remote repositories are connected, you can push your local changes to the remote repository using the git push command, and you can pull changes from the remote repository to your local repository using the git pull command. This allows you to collaborate with other developers and keep your local and remote repositories in sync. Once you're ready to push your changes to GitHub, you can run the following command:

git push origin master   # Pushes changes to the 'master' branch of the remote repository on GitHub

You may be prompted to enter your GitHub username and password to authenticate the push.

git remote add origin <remote-repo-url>
Here, "origin" is a common name used to refer to the remote repository, but you can choose any name you like.

Creating a New File in DevOps/Git and Adding Content to the "DevOps" Repository

In DevOps, Git is a popular version control system that enables teams to collaborate on projects. One of the basic tasks in Git is creating a new file and adding content to a repository. In this blog post, we will explore how to create a new file in DevOps/Git and add content to the "DevOps" repository.

Step 1: Create a New File in DevOps/Git

To create a new file in DevOps/Git, you need to follow these steps:

  1. Open the Git Bash or command prompt.

  2. Navigate to the directory where you want to create a new file. For example, if you want to create a new file in the "DevOps" repository, you can navigate to that repository using the following command:

     Copy codecd DevOps
    
  3. Once you are in the correct directory, you can create a new file using the following command:

     Copy codetouch Day-02.txt
    

    This command will create a new file named "Day-02.txt" in the current directory.

How to do Git push pull requests - YouTube

Step 2: Adding Content to the "DevOps" Repository

Now that you have created a new file in the "DevOps" repository, you can add content to it using the following steps:

  1. Open the Day-02.txt file in a text editor and add some content to it.

  2. Save the changes to the file.

  3. In the Git Bash or command prompt, navigate to the "DevOps" repository using the following command:

     cd DevOps
    
  4. Use the following command to stage the changes to the file:

     git add Day-02.txt
    

    This command will stage the changes made to the "Day-02.txt" file.

  5. Use the following command to commit the changes to the repository:

     git commit -m "Added new file Day-02.txt"
    

    This command will commit the changes to the "DevOps" repository with a commit message "Added new file Day-02.txt".

  6. Finally, use the following command to push the changes to the remote repository:

     git push origin main
    

    This command will push the changes to the "DevOps" repository on the "main" branch.

Congratulations! You have now created a new file in DevOps/Git and added content to the "DevOps" repository. By following these steps, you can easily collaborate with your team and manage your projects using Git.

480+ Devops Team Stock Photos, Pictures & Royalty-Free ...

0
Subscribe to my newsletter

Read articles from Subho Dey directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Subho Dey
Subho Dey

"DevOps engineer with a passion for continuous improvement and a drive to build better software, faster. I'm a strong believer in the power of collaboration, automation, and agile methodologies to transform the world of software development and delivery. My expertise includes continuous integration and delivery, infrastructure as code, Docker, Kubernetes, and configuration management. Follow along as I share my insights and experiences on Hashnode and let's build better software, together!"