Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git and Github Pages #15

Merged
merged 8 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions pages/hack-school/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"index": "Welcome to ACM Hack School!",
"logistics": "Hack School Logistics",
"git-github": "Git/GitHub",
"css": "Week 1: HTML & CSS",
"js": "Week 2: JavaScript"
}
181 changes: 181 additions & 0 deletions pages/hack-school/git-github.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Git/GitHub

## What is Git?

Git is a distributed version control system that enables developers to manage code changes, collaborate on projects, and maintain a history of revisions. It allows multiple developers to work on a project simultaneously and provides tools for tracking changes over time.

### Why do we need Git? (What is Version Control?)

Version control is essential in software development to track changes, manage collaborative work, and maintain a history of revisions. Without version control, managing code changes becomes complex, error-prone, and challenging to collaborate on. Git offers a structured approach to version control, making it easier to work in teams, track changes, and revert to previous versions if needed.

### Key Concepts in Git

AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
#### Repositories

A Git repository is a centralized location where your codebase and its complete history of changes are stored. It contains all versions of your files, branches, and commits.

#### Commits

Commits in Git are snapshots of your code at a specific point in time. Each commit has a unique identifier, a timestamp, and a message describing the changes made. Commits provide a detailed history of the project's development.

#### Branching

Branching allows developers to create separate lines of development within a repository. The main branch (often 'master' or 'main') serves as the foundation. Feature branches are created for specific changes, enabling developers to work on features without affecting the main branch.
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved

#### Merging

Merging is the process of integrating changes from one branch into another. After changes are complete in a feature branch, they are merged back into the main branch. Conflicts may arise during merging, requiring resolution.

### Common Git Commands
1. `git init`: Initializes a new Git repository.
2. `git clone <repository>`: Creates a local copy of a remote repository.
3. `git add <file>`: Stages changes for commit.
4. `git add --all`: Stages all modified files
5. `git commit -m "message"`: Commits staged changes with a message.
6. `git pull`: Fetches and merges changes from a remote repository.
7. `git push`: Pushes local commits to a remote repository.
8. `git branch`: Lists existing branches.
9. `git checkout <branch>`: Switches to a different branch.
10. `git merge <branch>`: Merges changes from one branch into the current branch.

For full documentation for all git commands check this [link](https://git-scm.com/docs/git#_high_level_commands_porcelain) out

### Git Instalation (Windows)
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved

You can follow this [guide](https://github.com/git-guides/install-git) or follow the instructions below

1. Go to this [link](https://git-scm.com/download/win) and click on the blue `Click here to download` at the top of the page. This should download an exe file.
2. Run the exe file
3. It will ask for permission to make changes to your device, select `YES`
4. Click `Next` then choose installation location (leave as default unless you have a reason not to) then press `Next` again
5. You will be able to choose many options, leave all the defaults unless you have a reason not to. Click `Next` untill you get the `Install` button, click it.
6. Then wait for installation and hit `Finish`
7. Veriffy that it was correctly installed by opening any command prompt and typing:
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
```sh copy
git --version
```
If everythting worked correctly it should print something like this:
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
`git version 2.41.0.windows.3`

You now have git installed on your Windows machine!!

## What is GitHub?

GitHub is a web-based platform built on top of Git. It provides an interface for hosting and collaborating on Git repositories. GitHub offers additional features, such as issue tracking, project management, and social interaction among developers.

### Creating a GitHub Account

1. Go to https://github.com/
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
2. Click on the `Sign Up` button at the top right
3. Add your email address
4. Create a Password
5. Choose your Username
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
6. Choose if you want updates and announcements
7. Play the game to verify that you are human
8. Hit the `Create Account` button
9. Verify email with the code sent to your inbox and input it
10. You now have your own GitHub Account!!

## Git/GitHub Workflow

#### Creating a Repository

**Using GitHub:**
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved

1. On GitHub, log in to your account.
2. Click the '+' sign in the top right corner and select 'New Repository'.
3. Provide a repository name, description, and other settings as needed.
4. Click 'Create repository'.

**Using Git:**

1. Open your command line or terminal.
2. Navigate to the directory where you want to create the repository.
3. Use the following commands:
```sh copy
git init
git remote add origin <repository_url>
git pull origin main
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
```

AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
#### Making Commits

AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
**Using GitHub:**
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved

1. On your repository's GitHub page, navigate to the file you want to change.
2. Click the pencil icon to edit the file.
3. Make your changes directly in the editor.
4. Scroll down and provide a commit message.
5. Click 'Commit changes'.

**Using Git:**

1. Make changes to your code.
2. Use the following command to stage changes for commit:
```sh copy
git add <filename>
```
Or use `git add --all` to stage all changed files
```sh copy
git add --all
```
3. Use the following command to commit changes with a message:
```sh copy
git commit -m "Commit message"
```

#### Pushing Changes

**Using GitHub:**

1. After committing changes on GitHub, they will be automatically pushed to the repository.

**Using Git:**

1. After committing your changes, use the following command to push them to a remote repository on GitHub:

```sh copy
git push origin main
```

AVERGNET marked this conversation as resolved.
Show resolved Hide resolved
#### Creating a Branch

**Using GitHub:**
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved

1. On your repository's GitHub page, click the `Branch: main` button.
2. Enter a name for your new branch and click `Create branch`.

**Using Git:**

To create a new branch and switch to it, use the following commands:
```sh copy
git checkout -b new-feature
```
This command creates a new branch called new-feature and switches to it.

#### Merging New Branch with Main

**Using GitHub:**
AVERGNET marked this conversation as resolved.
Show resolved Hide resolved

1. On your repository's GitHub page, navigate to the 'Pull requests' tab.
2. Click 'New pull request'.
3. Set the base and compare branches for the pull request.
4. Click 'Create pull request'.
5. Review the changes and click 'Merge pull request'.

**Using Git:**

1. Switch to the main branch:
```sh copy
git checkout main
```
2. Merge the new branch into the main branch:
```sh copy
git merge new-feature
```
3. Resolve any merge conflicts if they occur.
4. Push the changes to the remote repository:
```sh copy
git push origin main
```

Loading