【代码托管】Github 使用

Github 在一年前使用过,后来由于SVN放弃了使用! 

准备

1、生成公钥

Linux User: 生产公钥:

ssh-keygen -t rsa -C "your_email@youremail.com"
cat .ssh/id_rsa.pub

Windows User: 下载并按照 http://msysgit.googlecode.com/files/Git-1.8.4-preview20130916.exe

注意:不要下最新版本的,上面有个bug.另外,在windons下装git bash,可以实用Unix下的命令!

生成Git Bash,打开,按照Linux的方法生成公钥

2、添加SSH Key

将生成的公钥拷贝,点击右上角的小扳手图标


在新窗口中打开SSH Keys-->Add SSH Key


3、检查公钥

$  ssh -T git@github.com
Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa':
Hi ieczw! You've successfully authenticated, but GitHub does not provide shell access.
说明已经公钥已经添加成功了!

4、全局配置

git config --global user.name "your name"
git config --global user.email "your_email@youremail.com"

项目创建

登陆:https://github.com/

按照下面步骤设置:




这样一个工程创建完毕!

本地同步工程

在github.com创建完工程后会出现:

Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/ieczw/Test.git
git push -u origin master

Push an existing repository from the command line

git remote add origin https://github.com/ieczw/Test.git
git push -u origin master

先不管,后续代用。

在Git Bash上,或者Linux上执行如下命令!

Administrator@-RAIN /e/github
$ ls
Mp3-Player

Administrator@-RAIN /e/github
$ git clone https://github.com/ieczw/Test.git
Cloning into 'Test'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done

Administrator@-RAIN /e/github
$ ls
Mp3-Player  Test
这样已经把工程同步到自己的PC上了。

工程上传

把自己想要同步的工程copy到这个目录下面!然后添加到本地git里面

Administrator@-RAIN /e/github/Test (master)
$ git add src

Administrator@-RAIN /e/github/Test (master)
$ git commit -m "Add src for Test"
[master (root-commit) 4cd3bd9] Add src for Test
 67 files changed, 11090 insertions(+)
 create mode 100644 src/01string.c
 create mode 100644 src/01string.exe
 create mode 100644 src/12.txt
 create mode 100644 src/aa.c
 create mode 100644 src/aa.exe
 create mode 100644 src/add.c
 create mode 100644 src/all.c
 create mode 100644 src/all.exe
 create mode 100644 src/alnum.c
 create mode 100644 src/alnum.exe
可能在上传的时候遇到这个问题:

Administrator@-RAIN /e/github/Test (master)
$ git remote add origin https://github.com/ieczw/Test.git
fatal: remote origin already exists.
删除后重新add

Administrator@-RAIN /e/github/Test (master)
$ git remote rm origin

Administrator@-RAIN /e/github/Test (master)
$ git remote add origin https://github.com/ieczw/Test.git

如果这样删除之后还不行的话,进入.git/config,删除下面这两行:

[remote "origin"]
        url = https://github.com/ieczw/Test.git
        fetch = +refs/heads/*:refs/remotes/origin/*

接下来用git push上传(git pull 是更新本地)

Administrator@-RAIN /e/github/Test (master)
$ git push -u origin master
Username for 'https://github.com': ieczw
Password for 'https://ieczw@github.com':
Counting objects: 70, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (69/69), done.
Writing objects: 100% (70/70), 4.58 MiB | 62.00 KiB/s, done.
Total 70 (delta 28), reused 0 (delta 0)
To https://github.com/ieczw/Test.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
这样我们就可以在网页上看到我们的东西了!


GitHub的实用之处

1、比如你误删除了那个文件或者文件夹,可以用checkout找回。

Administrator@-RAIN /e/github/Test (master)
$ ls
src

Administrator@-RAIN /e/github/Test (master)
$ rm src/ -r

Administrator@-RAIN /e/github/Test (master)
$ ls

Administrator@-RAIN /e/github/Test (master)
$ git checkout src

Administrator@-RAIN /e/github/Test (master)
$ ls
src
如果你还用了git rm src,只要没有上传到远程github上,[git push]。我们还可以找回

git pull

git checkout src

一些实用的教程和一些问题的解决办法:

1、github教程(有点地方有点小问题):http://wuyuans.com/2012/05/github-simple-tutorial/

2、出现“GIT_DISCOVERY_ACROSS_FILESYSTEM not set”怎么办?

http://hi.baidu.com/hengbo0926/item/ffd8bc30edec4f697c034b62

3、GitHub错误处理:fatal:could not read Username for 'https://github.com': No such file or directory

http://blog.csdn.net/haipaner/article/details/18776759

4、如何删除项目工程

http://www.cnblogs.com/dyllove98/p/3221872.html

相关文章
相关标签/搜索