教你怎么上传本地代码到github
第一步:建立git倉庫
cd到你的本地項目根目錄下,執行git命令
?git init?
第二步:去github上創建自己的Repository,創建完成后拿到創建的倉庫的https地址
第三步:將本地的倉庫關聯到github上
例如:?git remote add origin https://github.com/dinphy-dev/sudamod_frameworks_base-oms.git?
第四步:將項目的所有文件添加到倉庫中
?git add .?
如果想添加某個特定的文件,只需把.換成特定的文件名即可
第五步:上傳github之前,要先pull一下,執行如下命令:
?git pull origin master?
第六步:將add的文件commit到倉庫
?git commit -m "init commit"?
第七步,也就是最后一步,上傳代碼到github遠程倉庫
?git push -u origin master?
執行完后,如果沒有異常,等待執行完就上傳成功了,中間可能會讓你輸入Username和Password,你只要輸入github的賬號和密碼就行了
Git 一些錯誤的解決方法
1. Pull is not possible because you have unmerged files.
癥狀:pull的時候
$ Git pull
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'
應該是因為local文件沖突了
解決方法:
1.pull會使用git merge導致沖突,需要將沖突的文件resolve掉
git add -u
git commit
git pull
2.如果想放棄本地的文件修改,可以使用git reset --hard FETCH_HEAD,FETCH_HEAD表示上一次成功git pull之后形成的commit點。然后git pull.
注意:
git merge會形成MERGE-HEAD(FETCH-HEAD) 。git push會形成HEAD這樣的引用。HEAD代表本地最近成功push后形成的引用。
就我的經驗,有時候會莫名其妙地出現這種狀況,而且Untracked files 還特別多(實際上自己可能只改了一兩個文件),所以只好先保存好自己確定做出的local的修改,然后用git reset --hard FETCH_HEAD回到上次成功pull之后的點,然后再pull就沒有問題了
2.You are not currently on a branch.
癥狀:有一次pull的時候又出現沖突,這回用“git reset --hard FETCH_HEAD”方法都不行了,出現:
$ git pull
You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
解決方法:
首先
git checkout -b temp
其次
git checkout master
即可恢復到master repository的狀態,然后就可以pull了
轉載于:https://www.cnblogs.com/dinphy/p/5618980.html
總結
以上是生活随笔為你收集整理的教你怎么上传本地代码到github的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OC系列foundation Kit基础
- 下一篇: mysql安装中出现的问题,