Step-by-Step Guide
- 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
- Install Git
Install Git using theyum
package manager:
sudo yum install git -y
- Verify Git Installation
Check the Git version to ensure it is installed correctly:
git --version
You should see the Git version information displayed.
- Configure Git
Set up your Git username and email address, which will be associated with your commits. Replaceyour_name
andyour_email
with your actual name and email address:
git config --global user.name "your_name"
git config --global user.email "your_email"
- Verify Git Configuration
Verify your Git configuration settings:
git config --list
- 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
- Clone an Existing Git Repository
To clone an existing Git repository, use thegit clone
command followed by the repository URL:
git clone https://github.com/username/repository.git
- 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"
- Check Repository Status
To check the status of your repository, use the following command:
git status
- Create a Branch
To create a new branch, use the following command:git branch mybranch
Switch to the new branch:git checkout mybranch
- 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
- Push Changes to a Remote Repository
To push your changes to a remote repository, use the following command:git push origin main
Replacemain
with the name of the branch you want to push. - Pull Changes from a Remote Repository
To pull changes from a remote repository, use the following command:git pull origin main
Replacemain
with the name of the branch you want to pull. - 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). - Use SSH URLs for Repositories
When cloning or adding remote repositories, use the SSH URL:bash git clone [email protected]:username/repository.git