# How to use Git and GitHub in Linux  on Red Hat systems

### 1\. **Install Git (if not already installed)**

First, install Git on your Linux system using the following command (Ubuntu/Debian):

```bash
sudo yum update
sudo yum install git
```

Please see this as a reference

[https://software-engineer.thirdygayares.com/package-manager-in-linux](https://software-engineer.thirdygayares.com/package-manager-in-linux)

---

### **Configure Git**

Before using Git, set your name and email:

```bash
git config --global user.name "Thirdy Gayares"
git config --global user.email "gayaresthird@gmail.com"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726116649256/91f648b0-ef1f-475a-995b-851713c3a54c.png align="center")

---

### **Create a Repository**

You can create a new Git repository (repo) in your project directory.

* **Create a Directory**
    
    ```bash
    mkdir myRepository
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726116801924/7c36051f-66f4-4f69-a62a-89672118d178.png align="center")
    

* **Navigate to your project folder:**
    
    ```bash
    cd myRepository
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726116885505/b6db4f71-5fd2-4666-9804-dbc442dfbe3b.png align="center")
    

---

### **Initialize the Git repository:**

```bash
git init
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726117071413/a402dd38-d988-4feb-9367-b6253d0ad4b3.png align="center")

---

### Create File

How to create a file in Linux? [https://software-engineer.thirdygayares.com/linux-basic-commands#heading-create-a-file](https://software-engineer.thirdygayares.com/linux-basic-commands#heading-create-a-file)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726117200831/763d0b88-75c8-4b62-be86-fbbd553220d6.png align="center")

---

### Git Status

This will show you the changes in your working directory, such as new files or modified files.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726117252111/392aa172-07b2-41b6-a612-3b56397c6ae0.png align="center")

---

### Add Files to Staging Area

```bash
git add .
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726117332373/43e552a1-dde3-4d30-96cd-e886953eb048.png align="center")

---

### Commit Changes

Once the files are staged, you can commit them. A commit is like saving a snapshot of your project at that point.

```bash
git commit -m "Initial commit with project files"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726117612366/b2ffd5b9-f685-4a73-9862-a930fdb48b93.png align="center")

---

### Check Commit History

You can see your commit history with:

```bash
git log
```

---

### Set Up Github Repository

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724679312491/656e5ec5-2b97-4847-9e75-131bcc87e2a4.png?auto=compress,format&format=webp align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724679321860/e8433b22-6d5e-4b45-90f9-55d9bbff8f89.png?auto=compress,format&format=webp align="left")

---

### Push to a Remote Repository

You can push your changes.

**Add a remote repository:**

```bash
git remote add origin https://github.com/Thirdy-Lecture/Github_Push_Example_2.git
```

**Push changes to the remote repository:**

```bash
git push -u origin master
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726118264347/8a8e63f3-b404-4da0-9c7e-8e69b1c28bca.png align="center")

How to resolve this issue ?

Go to [https://github.com/settings/tokens](https://github.com/settings/tokens)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726118433565/59fdebaa-498e-45e1-b7d8-40e075856d9d.png align="center")

Choose classic

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119036641/8a418a9b-f27c-461d-9a7e-3a573bfc5d3c.png align="center")

Check The Repo and Set note and Expiration then click generate token

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119085348/36033a21-2ddb-448a-8228-5101a4c07ee0.png align="center")

Copy and paste the token key

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119153613/7e8092b6-f735-44a9-b5b7-2bfa1b69e147.png align="center")

```bash
git push -u origin master
Username for 'https://github.com': thirdgyayares
Password for 'https://thirdgayares@github.com': <Paste your Personal Access Token here>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119262421/12438583-2fd3-4bc0-8032-5507a3b27a42.png align="center")

### Set up Credential Caching

If you don’t want to enter your token every time, you can cache your credentials using:

```bash
git config --global credential.helper cache
```

This will save your credentials for a while.

Alternatively, you can permanently store your credentials by using:

```bash
git config --global credential.helper store
```

This way, Git will store the credentials in a file, and you won’t be prompted for them again.

---

### Check the repository on your Github

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119348153/03e47f05-1e5b-4580-b43e-e39d42e9846a.png align="center")

I try to commit and push again

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119632207/94f00d99-bab4-4b27-b29a-002271fe2c5b.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119645573/110fb439-b600-4314-9139-9183006919c8.png align="center")

When I refresh my repository on github

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726119661148/7091ddd8-44e3-4c1f-b902-9dac17ed20ae.png align="center")

---

### Pull Changes from Remote

To pull updates from a remote repository:

```bash
git pull origin master
```
