Skip to the content.

What is Git & GitHub? – Basics & First Repo

🇯🇵 日本語版:01_Start.md

This section introduces you to Git and GitHub and goes over setting up your first repository.

Overview

Outline


What is Git?

What is Version Control?

History ⌛

Teamwork 💪

Backup 💾

A save point in a game 📌

Examples of Version Control

Google Docs Kintone
Google Doc Version History Kintone Record History

What is GitHub?

   
New GitHub Account New Repo

GitHub Example - Apple

Apple has released a set of tools and resources for free to help app developers, such as password manager makers, generate strong passwords.

github.com/apple/password-manager-resources

Apple publishes free resources to improve password security - ZDNet


Creating a Repository - Hands-on

Local setup

GitHub setup

Connect the local folder with GitHub


Create a Local Repository

⚠️ Make sure you have already completed the steps in the Prep Guide, Prep - 00_Prep_EN.md.

⚡ Where do you run the commands?

  1. Move to an easy-to-reach folder and create a directory named learning_git.

    cd Documents
    mkdir learning_git
    cd learning_git
    
  2. Use the pwd command to confirm you are in the right place.

    pwd
       
    /Users/YourUserName/Documents/learning_git
    
  3. Initialize a Git repository with the git init command.

    git init
       
    Initialized empty Git repository in /Users/YourUserName/Documents/learning_git/.git/
    

⚡ Repository is sometimes shortened to Repo.


Add a README.md File

  1. Create a README.md file.

    touch README.md
    
  2. Add a description of the repository to the README.md file.

    vi README.md
       
    # or
       
    code README.md
    
    # Learning JS Repo
    
    A repository for JavaScript lectures and assignments.
    

⚡ A README.md file is used to explain the purpose and usage of the software or the Git repository.


Confirm the Git Status

The git status command

Looking at the output, you can see that README.md needs to be tracked.

git status
On branch main
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
 README.md
nothing added to commit but untracked files present (use "git add" to track)

Add a File to the Staging Area

git add <file/folder>

git add README.md

README.md now exists in the staging area.

git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md

Add a File to the Git Repository

git commit -m "message"

README.md has been added to the repository!

git commit -m "README file created"

git status
$ git commit -m "README file created"
[main (root-commit) 03098e7] README file created
 1 file changed, 3 insertions(+)
 create mode 100644 README.md

$ git status
On branch main
nothing to commit, working tree clean

Create a GitHub Repository

Create a repository

Create a repository named learning_git.

Leave the Initialize this repository with a README.md checkbox unchecked.

Gif_GitHub_Repo_Demo

Local Git to GitHub

Let’s push the repository! Click the Clone or download button on GitHub, then copy the HTTPS link to get the URL.

git remote add origin <link>

git remote add origin https://github.com/Your_GitHub_UserName/learning_git.git
git push -u origin main

Result from the terminal

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 298 bytes | 298.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: This repository moved. Please use the new location:
remote:   https://github.com/ahandsel/learning_git.git
To https://github.com/ahandsel/learning_git.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

Debugging

When you set up your first repository to sync between local and GitHub, you may run into login problems.

  1. Remove the remote repository setting.

    git remote remove origin
    
  2. Create a new personal access token.
  3. Try again.

    git remote add origin https://github.com/Your_GitHub_UserName/learning_git.git
    git push -u origin main
    
  4. Check the repository on GitHub.com to confirm the push worked.
    • https://github.com/Your_GitHub_UserName/learning_git.git

Documentation


Hands-on A Complete

Initialize Git Set up GitHub Create and push the local repository
git init
git remote add origin
github.com/new git status
git commit -m

Overview of Basic Git Commands

How Git Saves Changes

There are two commands that move items between spaces:

There are three spaces where file and folder changes are saved:

01_Start_Git_Stages

   
  [ working directory ✍️ ]
  ↘️ git add 📥 ↘️
  [ staging area 📂 ]
  ↘️ git commit 💾 ↘️
  [ repository 🗄️ ]
  ↘️ git push 🔄 ↘️
  [ remote repository (GitHub) 🌐 ]

working directory, git add, staging area

   
➡️ [ working directory ✍️ ]
➡️ ↘️ git add 📥 ↘️
➡️ [ staging area 📂 ]
  ↘️ git commit 💾 ↘️
  [ repository 🗄️ ]
  ↘️ git push 🔄 ↘️
  [ remote repository (GitHub) 🌐 ]

working directory ✍️

git add 📩

staging area 📂


Wait, a staging area? 🤔

Imagine you are making music 🎶

To make a romantic album 🎶

git commit, repository, git push

   
  [ working directory ✍️ ]
  ↘️ git add 📥 ↘️
  [ staging area 📂 ]
➡️ ↘️ git commit 💾 ↘️
➡️ [ repository 🗄️ ]
  ↘️ git push 🔄 ↘️
  [ remote repository (GitHub) 🌐 ]

git commit 💾

repository 🗄️

What is Inside the Git Folder? 🤔

⚡ On Windows, use the dir command instead of ls.

$ pwd
/Users/UserName/Documents/learning_git

$ ls -la
total 8
drwxr-xr-x 4 UserName staff 128 Jun 9 14:54 .
drwx------@ 20 UserName staff 640 Jun 8 16:22 ..
drwxr-xr-x 12 UserName staff 384 Jun 9 14:56 .git
-rw-r--r-- 1 UserName staff 85 Jun 9 14:54 README.md

$ cd .git

$ ls -la
total 40
drwxr-xr-x 12 UserName staff 384 Jun 9 14:56 .
drwxr-xr-x 4 UserName staff 128 Jun 9 14:54 ..
-rw-r--r-- 1 UserName staff 20 Jun 9 14:54 COMMIT_EDITMSG
-rw-r--r-- 1 UserName staff 23 Jun 9 14:54 HEAD
-rw-r--r-- 1 UserName staff 316 Jun 9 14:56 config
-rw-r--r-- 1 UserName staff 73 Jun 9 14:54 description
drwxr-xr-x 14 UserName staff 448 Jun 9 14:54 hooks
-rw-r--r-- 1 UserName staff 137 Jun 9 14:54 index
drwxr-xr-x 3 UserName staff 96 Jun 9 14:54 info
drwxr-xr-x 4 UserName staff 128 Jun 9 14:54 logs
drwxr-xr-x 7 UserName staff 224 Jun 9 14:54 objects
drwxr-xr-x 5 UserName staff 160 Jun 9 14:56 refs

git push, remote repository

   
  [ working directory ✍️ ]
  ↘️ git add 📥 ↘️
  [ staging area 📂 ]
  ↘️ git commit 💾 ↘️
  [ repository 🗄️ ]
➡️ ↘️ git push 🔄 ↘️
➡️ [ remote repository (GitHub) 🌐 ]

git push <remote> <branch> 🔄

remote repository (GitHub) 🌐

Working with Remote Repositories

git remote add origin <link>

git remote

git remote --verbose

Documentation

git push?

git push <remote> <branch> 🔄

The git push command only works against a remote repository that has not changed since your last push or clone.

A Game Example - Animal Crossing

Documentation

Hands-on A Review

Saving with Git

  Music 🎶
[ working directory ✍️ ] Individual song
↘️ git add 📥 ↘️  
[ staging area 📂 ] Album
↘️ git commit 💾 ↘️  
[ repository 🗄️ ] Playlist
↘️ git push 🔄 ↘️  
[ remote repository (GitHub) 🌐 ] Spotify

git remote
The command to manage the connections between your local and remote repositories.

git push
The command to upload your local repository to the remote repository.

Quiz Time

  1. How are Git and GitHub related?
    • Hint: a hub is the central point of an activity or network.
  2. Which do you start with, git add or git commit?
    • Hint: to commit is to promise to a specific action (such as marriage).
  3. What is the git push command?
    • Hint: the git push command does the opposite of the git fetch command.
Answers 1. How is Git & GitHub related? * GitHub is the **hub** or the collection of everyone's Git * GitHub is a popular **remote repo** option 2. Which do you start with, `git add` or `git commit`? * First, use `git add` to gather the individual changes * Then, use `git commit` to bundle the changes 3. What is the `git push` command? * Use `git push` to upload the **commit** to the remote repo * Use `git fetch` to retrieve the latest version of the repo

Next Section

Create & Merge Branches - 02_Branches_EN.md

List of Lecture Guides

README_EN.md ⚙️