有的时候需要网上找好多文章才能搞对,所以自己记录对应的操作
一、第一次上传
初始化
git init
检测文件状态(有没有被追踪Untracked)
git status
追踪全部本地文件到暂存区
git add .
增加描述到git了
git commit -m '描述'
如果你没设置过 需先设置
git config --global user.name yourName
git config --global user.email yourEmail
绑定远程git地址
git remote add origin {远程仓库地址}
对应的移除命令:git remote remove origin
git remote -v
# Verifies the new remote URL
以下是有master分支需要拉取的情形,如果在服务器仓库未初始化分支,跳过拉取直接上传:
如果从未拉取过,使用git push -u origin master命令会出现错误如下:
$ git push -u origin master
To http://*:*/*.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'http://*:*/*.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.
需要拉取,使用git pull 出现如下错误:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
使用git pull origin master出现如下错误:
From http://*/test
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
需使用如下命令合并:
git pull origin master --allow-unrelated-histories
推送上去:
git push origin master:master
有很多按照网上说的都不好使,第一次上传我这是好用的