Skip to content
Merged

Dev #193

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 45 additions & 70 deletions src/routes/blogs/Gittutorial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import React from 'react';
import { Alert, Button, Card, CardContent, CardHeader, Typography, Link, List, ListItem, Divider, Box, Grid, Paper } from '@mui/material';
import gitarc from "../../assets/blog/images/git_arc.png"

*Please note that this assumes you have python and a code editor (Eg. vscode downloaded), and a github account.* <br/><br/>
*Please note that this assumes you have python and a code editor (Eg. vscode downloaded), and a github account.*

##### **What are Version Control Systems?**

Before we talk about Git, we need to talk about Version Control Systems (VCS). <br/><br/>
Before we talk about Git, we need to talk about Version Control Systems (VCS).

They enable developers to work simultaneously on the same project, experiment with new ideas, and easily revert to previous versions if needed. <br/><br/>

They are much more efficient than just sending code back and forth between developers and are essential in the Computer Science World. <br/><br/>
They enable developers to work on the same project, experiment with new ideas, and easily revert to previous versions.

They are much more efficient than just sending code back and forth between developers.

##### **Centralized vs Distributed**

Expand Down Expand Up @@ -39,176 +38,162 @@ There are two main types of VCS, centralized and distributed. <br/><br/>
<br/>
##### **Why is Git important?** <br/>

Git is a distributed VCS. <br/><br/>
It's a massively popular tool for managing projects among individuals and teams. <br/><br/>
Git is a distributed VCS, and its a massively popular tool for managing projects among individuals and teams.

Knowing how to use Git is an extremely important skill for any developer - and it will look great on your resume! <br/><br/>
Knowing how to use Git is an extremely important skill for any developer - and it will look great on your resume!

##### **Downloading Git**

First you will need to download Git onto your computer... You can do so through this [Git Download Link](https://git-scm.com/downloads) <br/><br/>
First you will need to download Git onto your computer... You can do so through this [Git Download Link](https://git-scm.com/downloads)

After installing it, start your terminal and type the following command to verify that Git is installed on your computer.
```bash

git --version

```
If everything went well, it should return the Git version that is installed on your computer. <br/><br/>
If everything went well, it should return the Git version that is installed on your computer.

##### **Configuring Git**

After installing Git onto your computer, you will need to configure it with your name and email address

```bash

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

```

This information is included in the commit metadata and helps identify who made a particular change in your project.<br/><br/>
This information is included in the commit metadata and helps identify who made a particular change in your project.

(Note this is done globally, so it will apply to all your repositories) <br/><br/>
(Note this is done globally, so it will apply to all your repositories)

If you want to change your name within a repository (so they wont affect any other ones),

You can use the following commands to set them, unset it, and also reconfigure them:

```bash

git config <key> <value>

git config --unset <key>

git config --unset-all <key>

```

*Where key is **user.name** or **user.email**.*

Note that --unset all is an option if you have multiple configurations. <br/><br/>
Note that --unset all is an option if you have multiple configurations.

If you want to unset your global configurations, you can use the following:

```bash

git config --global --unset <key>

```

##### **Initializing a Git Repository**

To start version controlling your project, navigate to your project's working directory (folder) using the terminal and run:

```bash

git init

```
This creates a new Git repository in your project directory.

This creates a new Git repository in your project directory. <br/><br/>

Make sure you are in the directory (folder) that you are planning to work in for the whole project. <br/><br/>
Make sure you are in the directory (folder) that you are planning to work in for the whole project.

##### **Adding files to your Repository**

To add files to the staging area (the area where changes to files are prepared before they are committed), you can use:

```bash

git add filename

```

Or if you want to add all of them at once, you can use:

```bash

git add .

```

##### **Committing a change to the repository**

Once you have added the files, you need to commit them to "save them',

```bash

git commit -m "Your commit message here"

```

Your message should be a brief description of the changes you have made to the project since the last commit. <br/><br/>
Your message should be a brief description of the changes you have made to the project since the last commit.

##### **Differences between Adding files and Committing changes**

When you are working on projects, there are three main areas that changes go through. <br/><br/>
When you are working on projects, there are three main areas that changes go through.

There is the **Working Directory** (where you are actually coding),

The **Staging Area** (where you prepare your changes in the next commit),

And the **Git Repository** (where you save your changes locally).

There is the **Working Directory** (where you are actually coding), the **Staging Area** (where you prepare your changes in the next commit) and the **Git Repository** (where you save your changes locally). <br/><br/>
###### **Working Directory to Staging Area:**

- **Working Directory to Staging Area:** Use **`git add`** to move changes from your working directory to the staging area, where you prepare what you want to include in the next commit. <br/><br/>
Use **`git add`** to move changes from your working directory to the staging area.

- **Staging Area to Git Repository:** Once you've finalized your changes in the staging area, use **`git commit`** to save those changes as a commit in the Git repository. <br/><br/>
*(Where you prepare what you want to include in the next commit)*

Committing will create a snapshot of your work in the Git log which you can go back to if you ever want to. <br/><br/>
Please see the diagram below: <br/><br/>
###### **Staging Area to Git Repository:**

Once you've finalized your changes in the staging area,

Use **`git commit`** to save those changes as a commit in the Git repository.

This will create a snapshot of your work in the Git log which you can go back to if you ever want to.

Please see the diagram below:

<img src={gitarc} alt="Git Tutorial Cover" style={{ width: "100%", height: "auto" }} />

##### **Branches**

Branches in Git allow you to work on different features or bug fixes without affecting the main code-base.<br/><br/>
Branches in Git allow you to work on different features or bug fixes without affecting the main code-base.

To create a new branch, you can use:

```bash

git branch new_branchname

```

*Great, you have created a new branch,*

*However you need to switch to that branch before you make any changes... to do so, use:*

```bash

git checkout new_branchname

```

Now you can start experimenting with your code without affecting your main code-base :<br/><br/>
Now you can start experimenting with your code without affecting your main code-base :

##### **Cloning a repository**

Cloning creates a local copy of a remote repository on your machine.

This allows you to work on the project, make changes (without affecting the remote repository).<br/><br/>
This allows you to work on the project, make changes (without affecting the remote repository).

Before you get started, ensure that you are in the working directory that you want to clone the online repository to.

To get the repository_url: <br/><br/>
To get the repository_url:

1\. Navigate to the repository you want to clone<br/><br/>
2\. Click the code button...<br/><br/>
3\. Copy the URL for the repository.<br/><br/>
3\. Copy the URL for the repository.

And then you have it, now to clone a repository you can use:

```bash

git clone repository_url

```

##### **Forking a Repository**

Forking involves creating a copy of a repository on your GitHub account. <br/><br/>
Forking involves creating a copy of a repository on your GitHub account.

Note this is different to cloning as the copy is on your GitHub account rather than your local repository. <br/><br/>
Note this is different to cloning as the copy is on your GitHub account rather than your local repository.

This allows you to freely experiment with changes without affecting the original repository. <br/><br/>
This allows you to freely experiment with changes without affecting the original repository.

Here's how you can fork a repository:

Expand All @@ -233,53 +218,43 @@ Here's how you can fork a repository:
Open your terminal and type `git clone`, then paste the URL you copied earlier. It will look like this, with your GitHub username instead of `YOUR-USERNAME`
```bash
git clone https://github.com/YOUR-USERNAME/repository_name

```

##### **Pushing changes to a Remote repository**

So far you have been working locally and haven't made your changes accessible to others. <br/><br/>
So far you have been working locally and haven't made your changes accessible to others.

To make your changes available, you need to push them to a remote repository. <br/><br/>
To make your changes available, you need to push them to a remote repository.

Note you will have to get the link of the repository you want to push the changes to before you do this. <br/><br/>
Note you will have to get the link of the repository you want to push the changes to before you do this.

To push your changes, use:

```bash

git remote add origin remote_repository_url

```

And then, do:

```bash

git push -u origin branchname

```

Where branchname is the branch you want to push to and origin is the name of remote repository name. <br/><br/>
Where branchname is the branch you want to push to and origin is the name of remote repository name.

##### **Checking Status / logs in Git**

Git has a command to check the status of your files, you can do so with the following:

```bash

git status

```

This will show you which files are modified, which files are staged for commit, and which files are untracked.<br/><br/>

If you want to check the a list of the commits that have been used, you can use:

```bash

git log

```

For additional resources, please head to the Github (docs) website.
Expand Down