创建新的repository 在github网站上
1. 点击网页右上的+,click New repository
2. 选取你希望repository创建的account
3. Type repository的名字和可选的description
4. 选取pubic or private 属性
5. 对于那些可选项,如果你是import an existing repository to github,那么不要选任何中的一个,否则会有冲突。你可以选择add 那些files 在command line。
6. Finish
Generating an SSH key
在命令行输入 ssh-keygen –C “yourhithbemail" –trsa
保存在默认路径下,无密码。
将默认路径下.ssh目录下的id_rsa.pub中的内容复制到github网站上。Account->setting->SSH and GPC keys->SSH keys
然后再ubuntu上看是否测通。
yanyang@ubuntu:~/.ssh$ ssh -Tgit@github.com
Hi hp! You've successfullyauthenticated, but GitHub does not provide shell access.
下面是我想将我Ubuntu本地的代码上传到github服务器上,因为我之前已经创建了一个repository,那么直接用一下命令即可:
yanyang@ubuntu:~/learngit$ git remote addorigin git@github.com:hp/mysqltest.git
yanyang@ubuntu:~/learngit$ git push -uorigin master
Warning: Permanently added the RSA host keyfor IP address '192.30.252.118' to the list of known hosts.
To git@github.com:hphpwj/mysqltest.git
![rejected] master -> master(fetch first)
error: failed to push some refs to'git@github.com:hp/mysqltest.git'
hint: Updates were rejected because theremote contains work that you do
hint: not have locally. This is usuallycaused by another repository pushing
hint: to the same ref. You may want tofirst integrate the remote changes
hint: (e.g., 'git pull ...') before pushingagain.
hint: See the 'Note about fast-forwards' in'git push --help' for details.
http://www.crifan.com/git_github_git_push_origin_master_error_failed_to_push_some_refs_to/
http://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to
这个是可以用以下方法解决:
yanyang@ubuntu:~/learngit$ git pull--rebase origin master
Warning: Permanently added the RSA host keyfor IP address '192.30.252.XXX' to t
warning: no common commits
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (3/3),done.
remote: Total 8 (delta 0), reused 0 (delta0), pack-reused 0
Unpacking objects: 100% (8/8), done.
From github.com:hphpwj/mysqltest
*branch master -> FETCH_HEAD
*[new branch] master -> origin/master
First, rewinding head to replay your workon top of it...
Applying: my first git project
Applying: remove printf
yanyang@ubuntu:~/learngit$ ls
mysql_test README.md
yanyang@ubuntu:~/learngit$ ll -tr
total 20
drwxr-xr-x 9 yanyang yanyang 4096 May 1405:55 ../
-rw-rw-r-- 1 yanyang yanyang 37 May 14 07:13 README.md
drwxrwxr-x 4 yanyang yanyang 4096 May 1407:13 ./
drwxrwxr-x 2 yanyang yanyang 4096 May 1407:13 mysql_test/
drwxrwxr-x 8 yanyang yanyang 4096 May 1407:13 .git/
yanyang@ubuntu:~/learngit$ git push originmaster
Counting objects: 9, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (8/8), 1.03 KiB | 0bytes/s, done.
Total 8 (delta 1), reused 0 (delta 0)
To git@github.com:hphpwj/mysqltest.git
0fe0c7d..7e2c19c master ->master
这个问题解决。但是我看有人竟然说用可以用以下命令解决:
git push -f
强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容。跟rm –f 强制删除一样。这样做很危险啊。