Git & Github Usage
Git is a very useful version management tool. Here note some common usage of git and github.
Outline
- Basic Description
- Installation
- Git Commands
1. Basic Description
(From wiki) Git is a distributed version-control system for tracking changes in source code during software development.
There are three main section of a Git project: the working directory, the staging area and the git repository.
working directory → add → staging area → commit → master
2. Git Installation
(1) Get and install file
Ubuntu:
$ sudo apt-get install git
Windows: install the exe file: https://git-scm.com/downloads
(2) Configuration:
Windows: Git->Git Bash, Ubuntu Shell
$ git config --global user.name "your user name"
$ git config --global user.email "youremail@gmail.com"
2. Git Commands
(1) init a git repo
$ git init
$ git add file
$ git commit -m "my message"
$ git status
$ git log
$ git rm test.txt
% git help
we can ignore unnecessary files or folders by adding it to the .gitignore file (create one if not existed)

Create .gitignore.txt in windows
–Create the file .gitignore.txt
–Right click on your current folder and select “open command window here”
–Type ren .gitignore.txt .gitignore
–Renaming the file via the command prompt allows the .name pattern
(2) branch
$ git branch newbranch # create a new branch
$ git checkout newbranch # enter the new branch
$ git branch -d newbranch # delete the new branch
$ git push -d origin newbranch # delere new branch in remote orign
3. Github
Github SSH Key
(1) Create SSH Key
Check the .ssh directory exist under the user main directory (git bash default path $ which git)
- If exist, check whether there exist the files of id_rsa and id_rsa.pub inside .ssh directory. If yes, skip to the next step.
- Otherwise, open the shell (Git Bash in Windows), create the SSH Key in the .ssh directory as follows:
$ ssh-keygen -t rsa -C youraccount@email
(2) add SSH Key in Github website
log into the github website,open “Account settings” -> “SSH Keys”:
Click the “Add SSH Key”,fill in anything meaningful in the ‘Title’ field,and paste the content of id_rsa.pub into the Key text form
Add Remote Repository
–“Create a new repo” online
# add remote github repository to origin
$ git remote add origin git@github.com:yourgithubname/reponame.git# can remove the added repository
$ git remote rm origin# Update remote refs along with associated objects
$ git push -u origin master (first time)
$ git push (after the first time)
Clone from remote repository
–$ git clone git@github.com:yangll0620/reponame.git