git 下载
在Git官方网站 ,选择适合自己电脑系统的git下载
git 基本用法
安装好git后就可以操作了,在桌面右击或者开始菜单中找到git bash启动命令窗口。
Git 全局设置:
git config --global user.name "ASxx"
git config --global user.email "123456789@qq.com"
创建 git 仓库:
mkdir wap // 项目在本地的路径
cd wap
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://git.oschina.net/name/package.git // 远程仓库地址
git push -u origin master
已有项目:
cd existing_git_repo
git remote add origin https://git.oschina.net/name/package.git
git push -u origin master
常见 error
笔者在使用git过程出现了-refusing to merge unrelated histories错误,经过一番摸索发现主要原因是本地仓库和远程仓库实际上是独立的两个仓库。
解决方法
在pull命令后紧接着使用–allow-unrelated-history选项来解决问题(该选项可以合并两个独立启动仓库的历史)。命令使用:
git pull origin master --allow-unrelated-histories
紧接着将本地仓库的提交推送到远程github仓库上就可以了,命令使用:
git push <远程主机名> <本地分支名>:<远程分支名>
出现git push报错error: failed to push some refs to 'git@github.com:原因是GitHub远程仓库中的README.md文件不在本地仓库中。
解决方案:
git push -u origin master
To git@github.com:xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xxx/xxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方案
git pull --rebase origin master
git push -u origin master
参考来源
[1] https://git-scm.com/docs
[2] https://blog.csdn.net/u012145252/article/details/80628451