Introduction to Git & Github


What’s git

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

What’s github

GitHub is a web-based Git repository hosting service. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project.

How to set up your git environment

Mac OS

Open Terminal, and follow the steps below skip step 1~2.

Windows

  1. Download Github Desktop for Windows
  2. Open Github Shell
  3. Config global setting
git config --global user.name "Jerry Shao"
git config --global user.email "jerryshao@example.com"
  1. Generate your ssh key
ssh-keygen -t rsa -C "youremail@example.com"
  1. Copy your ssh key
cd ~/.ssh
cat id_rsa.pub

How to set up your github account

Once your github account has been created, go to Settings - SSH&GPG Keys page, paste your ssh key as a new record.

Create your first open-source project

Create & initialize your git project

  1. Create a new repository on github.
  2. Create your project folder
mkdir ~/Test
  1. Initialize as a git project
cd ~/Test
git init

Remote with github project

Copy your github repository address

cd ~/Test
git remote add origin "your github repo address"

Add & commit your project code

  1. Create a new file
echo "This is my first git project" >> READEME.MD
  1. Add this file into your project temp storage
git add .
  1. Commit this file
git commit -m "This is my first commit"

-m: message for this commit.

Push to github

git push origin master

Once you finish these steps, your first git project is ready to view on github.