1.本地項目文件夾下初始化git項目
git init
2.爲本地項目添加別名爲 origin 地址爲[email protected]:williamvittso/.....的遠端倉庫
git remote add origin [email protected]:williamvittso/.....
3.推送
git push -u origin master
如果你遠端倉庫不是空的此處可能會報錯需要:
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 <remote> <branch>
或者乾脆設置成永久的: git branch --set-upstream-to=origin/<branch> master
然後你可能看到本地git拒絕拉取
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:williamvittso/timestamp.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 --allow-unrelated-histories