代码添加版本管理 初次上传代码到git及遇到问题和解决方案

一、在git上创建一个项目

二、提交代码命令

方法一:

1.github上面的仓库克隆到本地:git clone https://github.com/nameiyan/test.git(https://github.com/nameiyan/test.git替换成你之前复制的地址)

注:这个步骤后你的本地项目文件夹下面会多出个文件夹,把项目的代码复制到多出来的文件夹里

2.进入文件夹:cd test

3.git add .        (注:别忘记后面的 . ,此操作是把Test文件夹下面的文件都添加进来)

4.git commit  -m  "提交信息"  (注:“提交信息”里面换成你需要,如“first commit”)

5.git push -u origin master   (注:此操作目的是把本地仓库push到github上面,此步骤需要你输入帐号和密码)

方法二:

  Git global setup

git config --global user.name "用户名"
git config --global user.email "邮箱"

Create a new repository

git clone http://ip:port/root/policy-web.git
cd policy-web
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing folder

cd existing_folder
git init
git remote add origin http://ip:port/root/policy-web.git
git add .
git commit -m "Initial commit"
git push -u origin master

Existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin http://ip:port/root/policy-web.git
git push -u origin --all
git push -u origin --tags

三、遇到问题 

问题一:

! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://ip:port/root/policy-web.git'

出现这个问题是因为github中的README.md文件不在本地代码目录中,可以通过如下命令进行代码合并

git pull --rebase origin master

问题二:

fatal: remote origin already exists.

1、先删除远程 Git 仓库然后再添加

git remote rm origin

git remote add origin http://ip:port/root/policy-web.git

问题三:

Cloning into 'policy-web'...
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'http://ip:port/root/policy-web.git/'
1、在git身份验证中输入的账号或者密码不正确。

参考文件:初次使用git上传代码 - 躺在巨人肩膀上的小那 - 博客园

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值