进入需要版本管理的目录:
1. git init //初始化仓库
2. git add . //添加文件到本地仓库
3. git commit -m "提交内容的描述" //添加文件描述信息
4. git remote add origin //添加远程仓库地址,列如:git
remote add origin https://*.com.git
5. git pull origin master // 把本地仓库的变化连接到远程仓库主分支
6. git push -u origin master //把本地仓库的文件推送到远程仓库
遇到的问题:
一、'git' 不是内部或外部命令,也不是可运行的程序或批处理文件。
1.找到电脑里git的安装路径,例如:E:\Program Files\Git\bin
2.配置系统变量。右键“计算机-属性-高级系统设置-环境变量”在下方的“系统变量”中找到“path”点击编辑后将git的安装路径添加。
3.重新开启新的cmd输入git --version,出现版本信息则配置成功。
二、git push -u origin master
To https://*.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://*.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
To https://*.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://*.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
该问题是因为远程repository和本地的repository冲突导致的
解决方法:
1.使用强制push的方法:(不推荐,会导致版本库里的丢失)
git push -u origin master -f
git push -u origin master -f
2.push前先将远程repository修改pull下来
git pull origin master
git push -u origin master
git pull origin master
git push -u origin master