A Beginner's Guide to Installing Git, Using GitHub, and Uploading Code via Terminal
Tags: codenewbie, github
Published: 2023-07-23 09:27:15

## Introduction

Git and GitHub are effective tools that facilitate collaboration, streamline code management, and help developers in effectively maintaining their projects. In this blog post, I'm going to take you through the steps needed for installing Git, creating a GitHub account, and utilising the terminal for uploading your code.

## Step 1: Installing Git

Git is a distributed version control system that gives programmers the tools they need to effectively manage codebases, collaborate on projects, and track code changes. Multiple people can work at once, encouraging effective cooperation and version control.
First of all check for any previous installations of git o n your device using

```
git --version
```

If it is installed you will see your installed git version.
If not installed you can see which command fits your OS and use it appropreiately

For macOS:

Homebrew: If you have Homebrew installed, type the following command in your terminal

```
brew install git
```

You can also use Xcode command line tools to install git as such

```
xcode-select --install

```
For Linux:

```
sudo apt-get update
sudo apt-get install git
```

For Windows:

Download the Git installer from the official website (https://git-scm.com/download/win) and follow the installation wizard's instructions.

## Step 2: Creating a github account

If you don't have a GitHub account yet, visit [https://github.com](https://github.com) and sign up for a free account.

Step 3: Configuring Git

The following commands should be entered in your terminal after opening it, replacing "Your Name" and "your.email@example.com" with your actual information:


```
git config --global user.name "Your Name"
git config --global user.email your.email@example.com
```

Step 4: Create a new repository on GitHub

- Log in using your GitHub credentials.
- In the top right corner, select "New repository" by clicking the "+" symbol.
- Select whether you want your repository to be visible to the public or only to you and then click "Create repository."

Now open the directory where your code exists and open a terminal there.

```
cd /path/to/your/code
```

Initialize a new Git repository in this directory.

```
git init
```

Add your code files to the staging area

```
git add .
```

All of the files in the current directory are added by the dot (.). Replace the dot with the names of the files you want to add.

Commit the changes to your local repository with meaningful messages

```
git commit -m "Initial commit"
```

Now we need to connect your local git repo with te one you created in your github account. For that you need to copy the github repository url from the address bar. Now run the following command by placing the url in it.

```
git remote add origin <your_url>
```

Now finally push your code to the github repo using this command.

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

The -u option sets the upstream branch, so you can use git push in the future.

## Conclusion

You've learned how to use the terminal to upload your code to GitHub, set up a GitHub account, and installed Git successfully.
Hope this helps you in your development journey.