Git/Github
CSIE 瞿旭民
<kevinbird61@gmail.com>
Program Design - C++
http://slides.com/kevinbird61/deck-1
What is Git? Github?
- Git : tool , consider as interface between server and user.
- Github : data center of git , which has web service for user.
Why using Git?
- Back up the project
- Trace the project
- Work together
- and ...
Lots of tool support git
GUI tool for Git.
Editor tool for Git.
Test and deploy collaborated project.
... and so on.
(連結為簡易Github初步使用教學)
Installation
Windows、Mac
- Download from link
- All click the default choices is fine.
Linux
- Open your terminal (ctrl + t)
> sudo apt-get update
> sudo apt-get install git
- If your using CentOS or Fedora:
> yum install git
Overview
How does git work ?
Intro.
Repository
- Often represent as your project.
- The basic unit in git.
Commit
- Mostly contain all the current changes.
- User can record message represent each commit.
Branch
- Github allow different version from the same repo.
- If your project evolve with time, just like a tree grow up with lots of branch.
Diagram
Let's Practice!
Basic Setup
Basic
- Set up the user information with "git config"
- Using parameter "global" to let these setting globally
- If you want to upload your own project, you must do those settings.
> git config --global user.email "your@email.com"
> git config --global user.name "your_git_account"
> git config -l
user.email=your@email.com
user.name=your_git_account
- Windows have Git tool with GUI (Git Client, ... etc), also can do same tricks.
Git Command
Outline
Clone
- Everyone can download or clone any repository on github
- You can download the zip package, or using "git clone".
> git clone https://github.com/kevinbird61/tcp-requester.git
Cloning into 'tcp-requester'...
remote: Counting objects: 13, done.
remote: Total 13 (delta 0), reused 0 (delta 0), pack-reused 13
Unpacking objects: 100% (13/13), done.
Checking connectivity... done.
- After that, you can have this project on your own pc.
init
- Create a new repository (project)
- You can create repository by "git init"
- Use this when you want to add an existed project to a brand new repository on github.
[ Open terminal / git bash ]
> mkdir my_proj && cd my_proj
> git init
Initialized empty Git repository in /home/user/my_proj/.git/
.... (some operation , or ctrl+c+v an existed project in here)
> git add .
> git commit
> git remote add [remote_name/new_remote] [your repo url]
> git push -u [remote_name] [your repo branch]
... (authentication part , and if your network condition is fine, congratulate!)
status
> git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
- And then using "git status" to check out !
- This command will show all commit message !
- current stage of this repository: any changes、anything new will show in here
add、reset & commit
- When user accomplish their current work , then using "git add [project/files]" to add those new things.
- Also, you can discard above changes by "git reset [project/files]".
- And then using "git commit" to append some message on this changes stage.
commit message
Title
Blablabla
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
#
# Initial commit
#
# Changes to be committed:
# new file: test
- First line : Represent as commit title ( clarity for other to view your commit log )
- One blank line (format)
- The content of this commit stage.
- Other message generate automatically
log
- If you need to modify other's repo( or your old repo) , you will need to trace and find how this repo work, and its architecture.
- Then you can using "git log" to trace.
> git log
commit 1490ef5d2a7e09864278f3a88dc9996f71d8e62b
Author: kevinbird61 <kevinbird61@gmail.com>
Date: Thu Feb 23 01:16:14 2017 +0800
Revise connection channel problem.
- Fix the bugs - "can't make connection again to server by same network
location"
- Using socket.io room instead of namespace.
- Next step: build room monitor.
...
committer
committer's message
push & pull
- After appending messages on your current stage, we can now using "git push [remote name]" to upload this package to git server.
- Also , if your repository was upload another place, you can using "git pull [remote name]" to update your local old repository. ( Hint: If your local repository has changed before "git pull", there might generate conflicts and display error message. You can manually check and remove by yourself, or let git server point out which parts are different. )
push & pull (conti.)
- As your first push, you must create an new branch and push.
> git push -u [remote_name] [branch_name]
- If you pull from some other branch in your project , you can't use default like "git pull", you have to give the target remote name and branch name.
> git pull [remote_name] [branch_name]
- check your remote : "git remote -v"
> git remote -v
origin https://github.com/<your_account>/<your_repo>.git (fetch)
origin https://github.com/<your_account>/<your_repo>.git (push)
checkout
- Change current branch by "git checkout [branch_name]", and then the repo will immediately change to target branch.
kevin@DESKTOP-0RERCE9:[~]$ ls
shell-script-usage test_proj tmp
kevin@DESKTOP-0RERCE9:[~]$ git clone https://github.com/kevinbird61/LifeGamer.git
Cloning into 'LifeGamer'...
remote: Counting objects: 15260, done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 15260 (delta 11), reused 0 (delta 0), pack-reused 15229
Receiving objects: 100% (15260/15260), 34.56 MiB | 1.65 MiB/s, done.
Resolving deltas: 100% (3947/3947), done.
Checking connectivity... done.
kevin@DESKTOP-0RERCE9:[~]$ ls
LifeGamer shell-script-usage test_proj tmp
kevin@DESKTOP-0RERCE9:[~]$ cd LifeGamer/
kevin@DESKTOP-0RERCE9:[~/LifeGamer]$ ls
LICENSE README.md Version 1.0.0 Version 2.0.0
kevin@DESKTOP-0RERCE9:[~/LifeGamer]$ git checkout backend
Branch backend set up to track remote branch backend from origin.
Switched to a new branch 'backend'
kevin@DESKTOP-0RERCE9:[~/LifeGamer]$ ls
backend-gui backend-master backend-slave Feature.md protopype-gui.ep
checkout (conti.)
- Also , you can checkout to any commit.
> git log
....
commit 041ab969cd5c61cddde51f3cf2a87c116b33c34b
Author: kevinbird61 <kevinbird61@gmail.com>
Date: Tue Mar 7 12:51:11 2017 +0800
Modify battle bugs.
Bugs: if target battle room is not existed , the battle command will
crash the render server; so add an checking mechanism to prevent from
it.
....
> git checkout 041ab96
Conclusion
Reference
Git/Github Tutorial
By Kevin Cyu
Git/Github Tutorial
Git basic guideline for program design course.
- 3,219