Skip to content

Commit

Permalink
chore: Update Theory with GIT
Browse files Browse the repository at this point in the history
  • Loading branch information
marc committed Aug 23, 2024
1 parent f740a29 commit 81b8224
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 0 deletions.
248 changes: 248 additions & 0 deletions Lecture_Notes/Git01-101.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# Git Tutorial: A Step-by-Step Guide

## Introduction

Git is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It allows multiple developers to work on a project simultaneously without interfering with each other’s work. This guide will walk you through the basics of Git, from installation to advanced features.

## Table of Contents

1. [Understanding Version Control](#understanding-version-control)
2. [Installing Git](#installing-git)
3. [Getting Started with Git](#getting-started-with-git)
4. [Basic Git Commands](#basic-git-commands)
- [git init](#git-init)
- [git clone](#git-clone)
- [git status](#git-status)
- [git add](#git-add)
- [git commit](#git-commit)
- [git push](#git-push)
- [git pull](#git-pull)
5. [Branching and Merging](#branching-and-merging)
- [Creating a Branch](#creating-a-branch)
- [Switching Branches](#switching-branches)
- [Merging Branches](#merging-branches)
6. [Collaborating with Others](#collaborating-with-others)
7. [Rebasing](#rebasing)
8. [Undoing Changes](#undoing-changes)
9. [Conclusion](#conclusion)

---

## Understanding Version Control

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. There are two main types of version control systems:

- **Centralized Version Control Systems (CVCS)**: A single server stores all the versions of the project files, and clients check out files from this central place.
- **Distributed Version Control Systems (DVCS)**: Each client mirrors the entire repository. This means that if any server dies, any of the client repositories can be copied back up to the server to restore it.

Git is a DVCS, which means every developer has a complete history of the project on their local machine.

## Installing Git

### On Windows

1. Download Git from [Git for Windows](https://gitforwindows.org/).
2. Run the installer and follow the instructions. Choose the default options unless you have a specific reason to change them.

### On macOS

You can install Git using Homebrew:

```bash
brew install git
```

Alternatively, you can install it as part of Xcode Command Line Tools:

```bash
xcode-select --install
```

### On Linux

For Debian/Ubuntu-based distributions:

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

For Fedora:

```bash
sudo dnf install git
```

To verify the installation, run:

```bash
git --version
```

## Getting Started with Git

### Setting Up Your Identity

After installing Git, the first thing you should do is set up your username and email address. Git uses this information to label the commits you make.

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

### Initializing a Repository

A Git repository is a directory that contains your project files and the history of all changes made to those files.

To create a new repository:

```bash
mkdir my_project
cd my_project
git init
```

This command creates a `.git` directory inside `my_project` that tracks changes.

## Basic Git Commands

### `git init`

This command initializes a new Git repository.

```bash
git init
```

### `git clone`

To clone an existing repository:

```bash
git clone https://github.com/user/repo.git
```

This command copies the repository from GitHub (or any other remote) to your local machine.

### `git status`

To check the status of your files in the working directory and staging area:

```bash
git status
```

### `git add`

To add a file to the staging area (preparing it for commit):

```bash
git add file_name
```

To add all changes:

```bash
git add .
```

### `git commit`

To commit the changes in the staging area:

```bash
git commit -m "Commit message"
```

### `git push`

To push your changes to a remote repository:

```bash
git push origin branch_name
```

### `git pull`

To fetch and merge changes from the remote repository:

```bash
git pull origin branch_name
```

## Branching and Merging

### Creating a Branch

To create a new branch:

```bash
git branch branch_name
```

### Switching Branches

To switch to a different branch:

```bash
git checkout branch_name
```

### Merging Branches

To merge a branch into your current branch:

```bash
git merge branch_name
```

## Collaborating with Others

When working with others, it's common to create branches for new features or bug fixes. Here's how you can collaborate:

1. **Create a new branch**: `git checkout -b feature_branch`
2. **Work on your changes** and commit them.
3. **Push the branch**: `git push origin feature_branch`
4. **Create a Pull Request** on GitHub for code review and merging.

## Rebasing

Rebasing is the process of moving or combining a sequence of commits to a new base commit. This can be useful for keeping a clean project history.

```bash
git rebase branch_name
```

## Undoing Changes

### Undo a Commit

To undo the last commit (but keep the changes):

```bash
git reset --soft HEAD~1
```

To undo the last commit and discard the changes:

```bash
git reset --hard HEAD~1
```

### Discard Changes in a File

To discard changes in a specific file:

```bash
git checkout -- file_name
```

## Conclusion

This tutorial has covered the basics of Git, from installation to more advanced topics like branching, merging, and rebasing. By mastering these commands and concepts, you'll be well on your way to managing your projects efficiently with Git.

For more detailed information, consult the [official Git documentation](https://git-scm.com/doc).

---


Binary file added Lecture_Notes/PDFs/Git01-101.pdf
Binary file not shown.
Binary file modified Lecture_Notes/PDFs/README.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions Lecture_Notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Welcome to the **Lecture Notes**. This directory contains a collection of markdo
- [**PythonE-Path and Filehandling.md**](PythonE-Path%20and%20Filehandling.md)
Covers file handling in Python, including reading, writing, and manipulating files and directories.

- [**GIT**](Git01-101.md)
An introduction to Git, explaining version control, repositories, and basic commands.

## Additional Resources

- **htmls/**: Contains HTML versions of the notes, if available.
Expand Down

0 comments on commit 81b8224

Please sign in to comment.