一、在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身份验证中输入的账号或者密码不正确。