Fundamental Concepts of Git and GitHub for DevOps

Git and GitHub are essential tools in DevOps, fostering collaboration, version control, and automation in software development.

Fundamental Concepts of Git and GitHub for DevOps

Git and GitHub:

Git and GitHub are essential in the field of DevOps because they provide version control, collaboration, automation, and integration capabilities. These tools allow DevOps teams to efficiently perform continuous integration, continuous deployment, and infrastructure automation, resulting in faster and more reliable software delivery.

In simple terms:

Git is like a digital notebook that keeps track of all the changes you make to your computer programs. It helps you see what you did and when you did it.

GitHub is like a website where you can save and share your digital notebooks with others. It's like working on a project with your friends and keeping your notes in one place so everyone can see and work on them together.

Install Git:

For Windows:

  1. Visit the official Git website: Git for Windows.

  2. Click on the download link to start downloading the Git installer for Windows.

  3. Once the download is complete, double-click the downloaded file to run the installer.

  4. During the installation process, you'll be prompted to make several choices. The default options are usually fine for most users, so you can just click "Next" or "Install" to proceed.

  5. Git will be installed on your computer. After the installation is complete, you can open Git Bash from the Start menu to access the Git command-line interface.

For macOS:

  1. Git is pre-installed on macOS, so you can check if Git is already installed by opening the Terminal application and typing git --version. If Git is installed, it will display the version number.

  2. If Git is not installed, you can install it using Homebrew, a package manager for macOS. First, install Homebrew if you haven't already. Open Terminal and enter the following command:

     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  3. Once Homebrew is installed, you can install Git by entering the following command in Terminal:

     brew install git
    
  4. Git will be installed on your macOS system. You can verify the installation by typing git --version in Terminal.

For Linux (Ubuntu-based systems):

  1. Open a terminal window.

  2. Update the package list to make sure you have the latest information about available packages:

     sudo apt update
    
  3. Install Git by typing the following command:

     sudo apt install git
    
  4. Git will be installed on your Linux system. You can verify the installation by typing git --version in the terminal.

Once you have completed these steps, Git should be installed and ready to use on your computer.

Create a new repository on GitHub and clone it to your local machine:

After creating the repository, you can proceed to clone it to your local machine:

git clone <repository URL>

Some of the Important Git Commands:

  • git init is a Git command used to start a new repository. When you run git init in a specific directory, it initializes a new Git repository in that location.

  • git status is a command in Git that displays the status of changes in your working directory as untracked, modified, or staged.

  • git add is a command in Git that is used to stage changes for commit.

  • git commit saves your staged changes with a description, creating a snapshot of your project at a specific moment.

  • git restore reverts files in your working directory or unstages changes, allowing you to discard recent modifications and revert to a previous state.

  • git diff shows differences between your changes and the last commit, aiding in reviewing modifications before committing.

      git diff
    

    Output:

  • git log shows a history of commits in the repository, including commit messages and details.

      git log
    

    Output:

    • git log --oneline: Displays a concise version of the commit history, showing commit hashes and summaries.

    • git log --pretty: Shows detailed commit history, including authors, dates, and messages.

    • git log --oneline --pretty: Similar to git log --oneline, providing compact commit information.

  • git remote is a Git command used to manage remote repositories. It allows you to view, add, rename, and remove remote repositories associated with your local Git project.

    Link the Local Repository to GitHub:

      git remote add origin https://github.com/username/repository.git
    
    • git remote -v: Displays a list of remote repositories along with their URLs.

    • git remote add <name> <url>: Adds a new remote repository with a specified name and URL.

    • git remote rename <old-name> <new-name>: Renames an existing remote repository from <old-name> to <new-name>.

    • git remote remove <name>: Removes the remote repository with the specified name from your configuration.

  • git push is a Git command used to upload local repository changes to a remote repository.

      git push origin master
    
  • git fetch downloads changes from a remote repository into your local repository without merging them into your working directory, unlike git pull which merges changes automatically.

      git fetch origin master
      git pull origin master
    
  • git config --global is used to globally set configuration options for your user account.

      git config --global user.name "robinthakur00"
      git config --global user.email "robinthakur00@gmail.com"
    

    Happy learning (^_^)

Did you find this article valuable?

Support Devops Related Articles by becoming a sponsor. Any amount is appreciated!