Week 1 - Setup, tools, CLI and Git

Intro to the CLI

Files and folders

Paths

Basic scripting

Node.js Setup

VSCode setup

Intro to Git

Intro to Github

Markdown

Practice

Assignment

Back to core program

What is Github

When working on a large project with multiple developers, using Git is important to make sure we have a proper version control and avoid overwriting each others code. However, Git is a distributed version control system that works locally on your computer. You can optionally connect your local Git repository to a remote repository (for example on GitHub) to share and synchronise code with others.

Most developers choose GitHub because it makes collaboration and sharing code very easy. It hosts Git repositories in the cloud, so teams can work from anywhere and keep a single, always-available “source of truth” for their code. GitHub also adds useful tools around Git, like pull requests for reviewing changes, issues for tracking bugs and tasks, and actions for automating tasks. On top of that, it has a huge open-source community, which makes it simple to learn from others’ code and contribute to real projects.

A popular Github repository, you can see the project structure and browses the files.

A popular Github repository, you can see the project structure and browses the files.

<aside> ⌨️

Hands on: If you don't have a GitHub account, go to https://github.com and create one.

</aside>

Git vs Github

Git and GitHub are related but different:

You can use Git without GitHub, but GitHub is built to work with Git.

Open source software

Open source software is software where the source code is public. Anyone can view how it works, copy it, run it and modify it. Anyone can also contribute to an open source project and make it better.

This is different from “closed source” software, where the code is hidden and controlled by one company or person.

Why developers choose open source

Developers often choose open source because:

Notable open source projects

Here are three famous open source projects:

All of these are free to use, and thousands of people around the world help improve them.

<aside> ⌨️

Hands on: Open one of the open source projects above and look at the list of contributors on the right sidebar. Did you expect so many contributors?

</aside>

Setup Github

Before using Github, we need to setup a few things:

SSH key

The SSH key is like a very secure password stored on your computer. This key allows you to login to your GitHub account and gives you permission to modify your own code. It also prevents Git from asking for your GitHub username and password every time you push or pull code from GitHub.

Follow the instructions in the link below to generate a new SSH key. Make sure to select the OS you use (Mac/Windows/Linux).

  1. Generate a new key
  2. Add your SSH key to Github
  3. Test your SSH connection

Working with remote repositories

Cloning existing repository

To download existing Github repository, we use the command git clone:

git clone <https://github.com/Link/to/repository.git>

To clone a repository from Github, to to the repository → Click on the green Code button → SSH

SSH URL on Github

SSH URL on Github

SSH vs HTTPS

SSH uses your SSH key for authentication, while HTTPS requires you to enter your username and password every time you push or pull code. We recommend using SSH every time it is possible.

<aside> ⌨️

Hands on: Create a new repository on Github. Give it a nice name and add a README file. Then clone the repository to your computer. Open the folder in VSCode and make sure the README file is there.

</aside>

The difference between forking and cloning

Watch the following video to understand an important

https://www.youtube.com/watch?v=k0DWmw1nYnM

Key takeaways from the video:

Pushing code to Github

After cloning a repository, you can now work on the files locally: Make changes and commit with git commit . Once everything is committed, we want to push those commits to the remote repository on Github. To do so, use the command:

git push

<aside> 💡

You can push multiple commits at once

</aside>

<aside> ❗

Remember, git commit is saving your code locally and does not automatically push the changes to a remote server. You must use git push to save your changes on Github.

</aside>

What if someone else pushed their own changes to the repository? Then we have a handy command git pull to pull the latest changes from Git:

git pull

Git pull will download all the latest commits from the remote server (e.g Github) and apply them to your local copy. You will be able to see all the latest commits with git log .

<aside> ⌨️

Hands on:

  1. In your newly cloned repository, make changes to README file, commit the code and push it to Github. Verify the changes on github.com
  2. Go to your repository on Github, edit the README file directly from the website and commit (directly to the main branch). Afterwards, use git pull to download the latest commit from Github. Verify the changes in VSCode </aside>

Pull requests

A pull request (often called a PR) is a way to propose changes to a repository on GitHub. It's a request asking the repository owner or maintainers to review your changes and potentially merge them into the main codebase.

How it works

  1. You make changes in your own copy of the repository (a fork).
  2. You push those changes to GitHub.
  3. You open a pull request, describing what you changed and why.
  4. The repository maintainers review your code, leave comments, and may request changes.
  5. Once approved, your changes are merged into the main project.

The benefits