1. 首先在github上创建repository 我的仓库名叫 shellscript
2. 在Centos6.5上创建目录,加入README.md 简介,并git初始化
[root@nagios-client02 wzz]# cd wzz_git/
[root@nagios-client02 wzz_git]# lltotal 12
-rw-r--r--. 1 root root 15 Jan 28 20:41 1.txt
-rw-r--r--. 1 root root 10 Jan 28 21:04 2.txt
-rw-r--r--. 1 root root 7 Jan 28 21:04 README.md
[root@nagios-client02 wzz_git]# echo "# shellscript" > README.md
[root@nagios-client02 wzz_git]# cat README.md# shellscript
Reinitialized existing Git repository in /home/wzz/wzz_git/.git/
3. commit提交、把暂存区的所有内容提交到当前分支master
# On branch master
# Your branch is ahead of 'learngit/master' by 1 commit.
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README.md
#
no changes added to commit (use "git add" and/or "git commit -a")
4. 添加远程库:git remote add origin git@github.com:supermenxxx/shellscript.git
出现的问题(1)
fatal: remote origin already exists.
解决方法:
[root@nagios-client02 wzz_git]# git remote rm origin
5. 把本地库的内容推送到远程
[root@nagios-client02 wzz_git]# git push -u origin master
Git不但会把本地的master
分支内容推送的远程新的master
分支,还会把本地的master
分支和远程的master
分支关联起来,在以后的推送或者拉取时就可以简化命令。
推送成功后,可以立刻在GitHub页面中看到远程库的内容已经和本地一模一样:
出现的问题(2)
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/supermenxxx/shellscript.git/info/refs
fatal: HTTP request failed
解决方法(2)
[root@nagios-client02 wzz_git]# git remote set-url origin ssh://git@github.com/supermenxxx/shellscript.git[root@nagios-client02 wzz_git]# git push -u origin master
Counting objects: 7, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (7/7), 504 bytes, done.
Total 7 (delta 0), reused 0 (delta 0)
To ssh://git@github.com/supermenxxx/shellscript.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.