# Git and GitHub Essentials

### ✅Introduction

Git is a tool that allows you to version control. version control helps you to keep track of the files and folders means that it allows you to record modifications, additions, and deletions in your files and folder, creating a history of what operations were performed on which file or folder. It ensures the security of important data.

GitHub is a Web-based platform. It provides hosting for software development projects using the Git version control system. In this web platform, we can share code, track changes, and manage software development processes.

### ✅Create a new repository on GitHub and clone it to your local machine.📁

To create a repository and clone to the local machine following steps were performed-:

**Step-1:**Sign into your GitHub account or create a new one if you don't have an account.

**Step-2:**Click on the "+" sign in the top right corner of the GitHub website and select "New repository.

![github dashboard](https://cdn.hashnode.com/res/hashnode/image/upload/v1690449941335/ebf597c5-01bb-4056-9c39-ca2cc5c87f94.png align="center")

**Step-3:**Choose a name for your repository and, optionally, add a description. In this picture, I have created a new repository called theater-reservation-system.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690450272132/d94b9e2d-056d-429e-8add-953daf432e95.png align="center")

**Step-4:**Decide whether you want the repository to be public (visible to everyone) or private (accessible only to you and collaborators).

*Note-*:*You can also initialize the repository with a README file, which helps start a new project.*

**Step-5:**go to the folder which you have created in GitHub and go to the right side clone button click on it and copy the https link. In this picture, I have cloned the http link of the repository name Theater-reservation-system.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690452345439/e02b1ab9-0353-44c4-a4bb-6744e90a11c7.png align="center")

**Step-6:**Open your terminal or command prompt on your local machine or PC and enter the below command-

```plaintext
1.mkdir github
2.git clone <https link of that cloning folder>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690452665376/b560263a-9cb5-4300-9969-016039353ae1.png align="center")

you can see that theater-reservation-system repository was successfully cloned from GitHub to a local machine or PC.

### ✅Make some changes to a file in the repository and commit them to the repository using Git.🖥️

**Step-1:**Open your terminal or command prompt and navigate to the directory of the cloned repository using the **cd** command.

```plaintext
cd Achyut197
```

suppose I want to create a new file and perform all Git operations in the terminal.

```plaintext
1.git init
2.touch adb.txt
3.touch test.txt
```

`git init` command is used to initialize a new Git repository in a directory on your local machine. When you run `git init` in a directory, it sets up the necessary Git files and data structures, creating an empty repository that can now track changes to your project's files. In this example, I have initialized the git init inside the Achyut197 repository and also created two files using the `touch` command.

*Note-:when you initialized the git init command inside the repository all the git commands can easily perform all operations inside that repository only. If you perform all the git command operations on a simple repository that is not initialized by the git init command terminal will show you an error.*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690455364131/7d14ecd5-734a-4209-b49e-7a289dedc72f.png align="center")

**Step-2:**`git status` command will show you a list of all the modified files and any untracked files.

```plaintext
git status
```

**Step-3:**`git add` command adds the changes you made to the staging area, use the `git add` command followed by the filename or a dot to add all the modified files.

syntax:`git add <file name>`

```plaintext
git add adb.txt
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690456027186/065a8c21-df31-4cba-9f70-21dbd5a260ee.png align="center")

In this example, I have staged an adb.txt file on the branch 'ad' in the git commit process. You can see that that file name was shown on the terminal in green color means adb.txt file was staged and tracked by the git.

**Step-4:** To commit a file to git we can use the command is-

`git commit -m "Your commit message here"`

```plaintext
git commit -m "added successfully"
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690456635866/5e71e5d4-e57b-4f7d-8f43-73d24313a050.png align="center")

In this example, you can see that the adb.txt file was successfully committed to git. If anyone deletes the adb.txt file you can retrieve the file from git.

*Note-:when you perform the commit command operation in git you must give your user email id and username. To give the username and user email id following command was used.*

```plaintext
git config --global user.email "user email id"
git config --global user.name "user name"
```

### ✅Push the changes back to the repository on GitHub.📓

After completing the commit command operation then enter the git push command in the terminal. so all the repository of the local pc was pushed to Github web platform.

`git push <remote-name> <branch-name>`

Here remote name is 'origin' which is represented the remote URL of the GitHub web platform.

```plaintext
git push origin ad
```

here ad is the branch for the Achyut197 repository.

If it gives an error following operations was performed-:

```plaintext
git remote set-url origin http://<personal access token url><ssh url link of Github Repository>
```

<mark>To find personal access token go to github-&gt;settings-&gt;Devloper settings-&gt;personal access token-&gt;token(classic)-&gt;generate new token-&gt;generate new token (classic)-&gt;sign in account-&gt;give your token name and give your required permissions. so the personal access token URL was generated.</mark>

all the files and repositories were pushed to the GitHub repository.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690460019554/21def710-6f43-4d8c-ab3c-b8cccf4e985b.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690460175292/7d12d586-f17f-44ff-8efe-0b1478a30713.png align="center")

here Achyut197 repository was pushed successfully to the GitHub repository name Achyut197.
