Installation guides

Installing Git on RHEL

Step-by-Step Guide

  1. Update the Package Index
    Open a terminal and update the package index to ensure you have the latest information about available packages:
   sudo yum update -y
  1. Install Git
    Install Git using the yum package manager:
   sudo yum install git -y
  1. Verify Git Installation
    Check the Git version to ensure it is installed correctly:
   git --version

You should see the Git version information displayed.

  1. Configure Git
    Set up your Git username and email address, which will be associated with your commits. Replace your_name and your_email with your actual name and email address:
   git config --global user.name "your_name"
   git config --global user.email "your_email"
  1. Verify Git Configuration
    Verify your Git configuration settings:
   git config --list
  1. Create a New Git Repository
    To create a new Git repository, first create a directory for your project:
   mkdir myproject
   cd myproject

Initialize a new Git repository:

   git init
  1. Clone an Existing Git Repository
    To clone an existing Git repository, use the git clone command followed by the repository URL:
   git clone https://github.com/username/repository.git
  1. Add Files to the Repository
    To add files to your Git repository, first create or copy the files into your project directory. Then use the following commands to stage and commit the files:
   git add .
   git commit -m "Initial commit"
  1. Check Repository Status
    To check the status of your repository, use the following command:
   git status
  1. Create a Branch
    To create a new branch, use the following command: git branch mybranch Switch to the new branch: git checkout mybranch
  2. Merge Branches
    To merge changes from one branch into another, switch to the branch you want to merge into (e.g., main), and then use the following command: git checkout main git merge mybranch
  3. Push Changes to a Remote Repository
    To push your changes to a remote repository, use the following command: git push origin main Replace main with the name of the branch you want to push.
  4. Pull Changes from a Remote Repository
    To pull changes from a remote repository, use the following command: git pull origin main Replace main with the name of the branch you want to pull.
  5. Set Up SSH for Git (Optional)
    For added security, you can set up SSH keys for Git. Generate an SSH key pair: ssh-keygen -t rsa -b 4096 -C "your_email" Add the SSH key to the ssh-agent: eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa Copy the SSH key to your clipboard: cat ~/.ssh/id_rsa.pub Add the SSH key to your Git hosting service (e.g., GitHub, GitLab).
  6. Use SSH URLs for Repositories
    When cloning or adding remote repositories, use the SSH URL:
    bash git clone [email protected]:username/repository.git
Other Recent Posts