配置用户名和邮箱
查看用户名和邮箱地址
$ git config user.name
$ git config user.email
修改用户名和邮箱地址
$ git config --global user.name "username"
$ git config --global user.email "email"
查看git配置
$ git config --list
提交本地代码到远程
进入工作目录
git init
git add .
git commit -m 'init commit'
//关联远程仓库
//git push <远程主机名> <本地分支名>:<远程分支名>
git push origin master:master
或者执行
git push -u origin master(默认将当前分支推送到远程master分支同时指定origin为默认主机,
后面就可以不加任何参数使用git push了)
问题
-
error:src refspec master does not match any error: failed to push some refs to 'http://192.168.24.52:9010/monitor-plat/monitorplat.git' 可能的原因: 本地文件与github上的文件有冲突 本地需要提交的文件中存在空文件(可执行touch README) 解决方案: touch README git add README git commit -m "change" git push origin master 本地的origin和remote origin/master 没有建立关联 解决方案: git remote remove origin git remote add origin git@github.com:XXX/XXX.github.io.git git push origin master 仓库名称不一样,导致远程和本地的仓库不能关联上 解决方案: 重命名当前分支: git branch -m oldBranchName newBranchName
-
error: failed to push some refs to 'http://192.168.24.52:9010/monitor-plat/monitorplat-web.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. 原因:远程文件不在本地代码目录中 方案: 可以通过如下命令进行代码合并【注:pull=fetch+merge] git pull --rebase origin master
-
fatal:remote origin already exists 原因:origin已经存在 方案: git remote rm origin
-
fatal: refusing to merge unrelated histories 原因:不相关的分支相互合并 方案: git pull origin master --allow-unrelated-histories
原因:不相关的分支相互合并
方案:
git pull origin master --allow-unrelated-histories