Git tutorial

Written with StackEdit.

Github brief tutorial

Basic knowledge of git/github

  • Git: this is a software
  • Github: a websites do version control
  • Repository: the repository of stuff
  • commit: = SAVE. Every commit will create a hash
  • Branch: Make a big changepull request: merge branch to the mian branch
  • Fork

*open CMD

Configuring Github account:

git config -- global ""
git config -- global "haqin"

Cloning repository from remote

I want to clone a reposityory to local D:/Github/Project1

cd d:/Github/Project1
git clone

If you have a file to upload/download:

change the path to the repository (Gitbub project folder)
git status     (showing which files have changed)
git add test.txt   (I want to upload the file of "test.txt")
git status  (green file mean prepare to upload)
git commit -m "xxxxxxx"  (adding commit)
git push (upload file)

if you have multiple files (i.e. A1.txt, A2.txt) to push:

git add test A1.txt
git commit -m 'A1'
git add test A2.txt
git commit -m 'A2'
git push 

If you have files to download

change the path to the

git pull

Creating a subfolder in Git

  • create a subfolde in local
  • put a file (could be blank readme.txt), and push
  • the new subfolder will also be created in Server

UPload a whole project to a new Github

git init
git add .
git commit -m 'this is a AI project'
git remote add origin
git push -u origin master 


如果队友对文件进行了修改并且push 到master, 与我现在的编辑产生了冲突, 我应该先在本地建立一个branching, 然后 push 到 remote.

版本冲突的时候, 经常会出现一个error:

error: you need to resolve your current index first

解决的在branch之前, 需要解决的是:

git reset --merge

  • check the branch in git
git branch

  • create a branch and active locally
git checkout -b newBranchingName


git branch newBranchingName #相当于创建新的分支以及一个指针(初始指向master)
git checkout newBranchingName #相当于开始在分支工作,将指针移动到新创建的分支

每次使用check 进行切换之后,可以使用git branch 进行验证

注意,在以下的例子中,开辟分支以及合并可以仅仅是locally, 只有在最后一部进行git push.

$ git commit -a -m 'fixed the broken email address'
$ git checkout master
$ git merge hotfix  
$ git push 
# delete branch after merging 
$ git branch -d qinhaonew 
  • push the new created branch to remote
git add . 
git commit -m "xxxx" # if I have committed before, then I don't have to commit -it again
git push origin newBranchingName 
  • create a branch on the Github
  • Detele branch in Git:
git push origin --delete The_name_of_the_branch



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s