最近使用git命令从github克隆仓库到版本,然后进行提交到github时报错如下:
[[email protected] git_test]# git push origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/jsonhc/git_test.git/info/refs
fatal: HTTP request failed
这台本机没有配置与github的ssh密钥连接,直接通过的是httpds
1、确保不是git版本d低的问题
[[email protected] wadeson]# git --version
git version 1.7.1
2、从github克隆仓库到本地:
git clone https://github.com/jsonhc/git_test.git
[[email protected] wadeson]# git clone https://github.com/jsonhc/git_test.git
Initialized empty Git repository in /home/wadeson/git_test/.git/
remote: Counting objects: 20, done.
remote: Total 20 (delta 0), reused 0 (delta 0), pack-reused 20
Unpacking objects: 100% (20/20), done.
3、查看仓库内容,然后增加需要提交的文件
[[email protected] git_test]# ll
总用量 20
-rw-r--r--. 1 root root 712 7月 31 23:59 flask_first.py
-rw-r--r--. 1 root root 2766 7月 31 23:59 landing.py
-rw-r--r--. 1 root root 1881 7月 31 23:59 menu_list.py
-rw-r--r--. 1 root root 10 7月 31 23:59 README.md
-rw-r--r--. 1 root root 377 7月 31 23:59 total.py
[[email protected] git_test]# mv ../statistics_ip.py ./
[[email protected] git_test]# ll
总用量 24
-rw-r--r--. 1 root root 712 7月 31 23:59 flask_first.py
-rw-r--r--. 1 root root 2766 7月 31 23:59 landing.py
-rw-r--r--. 1 root root 1881 7月 31 23:59 menu_list.py
-rw-r--r--. 1 root root 10 7月 31 23:59 README.md
-rw-r--r--. 1 root root 377 8月 3 15:01 statistics_ip.py
4、git config --global user.name "json_hc"
git config --global user.email "[email protected]"
5、git remote set-url origin https://[email protected]/jsonhc/git_test.git
6、git add statistics_ip.py
git commit -m "add statistics_ip.py to statistics ip of nginx"
[[email protected] git_test]# git commit -m "add statistics_ip.py to statistics ip of nginx"
[master a460f0f] add statistics_ip.py to statistics ip of nginx
1 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 statistics_ip.py
7、git push -u origin master 第一次推送加上-u
[[email protected] git_test]# git push -u origin master
Password: 这里需要提供github的密码
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 276 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://[email protected]/jsonhc/git_test.git
8e23043..a460f0f master -> master
Branch master set up to track remote branch master from origin.
然后进入github网站查看已岁推送的文件了
现在使用另外的主机进行开发的时候,首先第一步:
git pull远程仓库的文件
[[email protected] git_test]# git pull origin master
Password:
remote: Counting objects: 2, done.
remote: Total 2 (delta 1), reused 2 (delta 1), pack-reused 0
Unpacking objects: 100% (2/2), done.
From https://github.com/jsonhc/git_test
* branch master -> FETCH_HEAD
Updating 8e23043..a460f0f
Fast-forward
statistics_ip.py | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 statistics_ip.py
[[email protected] git_test]# ll
total 24
-rw-r--r-- 1 root root 712 Aug 3 14:41 flask_first.py
-rw-r--r-- 1 root root 2766 Aug 3 14:41 landing.py
-rw-r--r-- 1 root root 1881 Aug 3 14:41 menu_list.py
-rw-r--r-- 1 root root 10 Aug 3 14:41 README.md
-rw-r--r-- 1 root root 377 Aug 3 15:24 statistics_ip.py
-rw-r--r-- 1 root root 377 Aug 3 14:41 total.py
这样才能保证不冲突,得到的是新的版本