[英]update my repository on github
我剛剛去了github在我的計算機上本地工作的項目。 一切順利,我可以上傳我的所有文件。現在我想知道如果我在本地對我的項目進行一些更改,我如何更新我的存儲庫嘗試以下命令:
git add.
git pull origin master
我想我忘記了什么,或者我使用的命令不正確,正確的方法是什么?
確保在“正常”情況下將更改正確添加到遠程 github 存儲庫的工作流程應遵循以下階段..
(1) git status
總是會告訴您什么是未提交的,什么需要“添加”(暫存)以提交到您的本地存儲庫。 事實上,git 會提示你它認為你工作流程的下一步是什么
(2) git add <your_file_path_you_can_use_glob_patternsLike_asteriks>
(3) git commit -m "A Nice Subject line for many file commits <enterFromKeyboardGivesYouAnotherLine>
(a) Continue typing more comments which are detailed if necessary <anotherEnterFromKeyboard>
(b) Some more details and do not forget to put closing quote mark"
如果使用 Windows git-bash.exe 則在 Windows 下工作它使用 mingW64 模擬器來模擬 linux 環境。 它非常擅長。
您需要提交您想要保留的任何更改 - 在本地之前您可以遠程“推送”您的更改到您的 github 存儲庫,即只有在您告訴 git 遠程 git 存儲庫在哪里之后...
(4) git remote add myGitHubOrBitBucketRepo https://github.com/YourGitAppRepo.git
通常,您在 github 上的遠程存儲庫的默認名稱是“origin”。 但是我一直在使用特定的別名分支名稱,在您的情況下是“myGitHubOrBitBucketRepo”
(5) git push -u myGitHubOrBitBucketRepo HEAD:master
此命令會將您提交的更改(也就是 git speak 中的快照)推送到 github.com 上的 YourGitAppRepo.git 到 master 分支上,如果您的遠程倉庫上的 master 不在您的本地分支之前,並且它只是后面的幾個提交- github.com 會接受這個推送
-u 與 --track 相同,這意味着位於 @ HEAD 的本地分支將跟蹤遠程別名 myGitHubOrBitBucketRep 處的主分支
在第 4 步和第 5 步中,您必須使用用戶 ID 和密碼與 GitHub.com 上的遠程存儲庫進行交互
(6) git status
從現在開始 git status 實際上會告訴你你是落后還是領先於你的遠程 github 倉庫,因為你在推送中做了 --track (ing) 選項
從現在開始使用的另一個有用的命令是
git branch -vv --all
一個例子
$ git branch -vv --all
* CurrAsOf18Jan2018 50d1fc6 [remotes/bitbucketFrmWin/master: behind 5] Pedantic but done - gitNotes.txt
remotes/bitbucketFrmWin/master 58470cd [CurrAsOf18Jan2018] This is really crazy - Spent more than a week - Singleton still gives
在這里,bitbucketFrmWin 是我遠程 bitbucket 存儲庫的別名 AsOf16Jan2018 是一個我不再感興趣的分支 master 是我當前的主分支,我將更改從本地存儲庫推送到它。
--all 選項還將顯示您的本地和您的“遙控器”
值得注意的是以下 * CurrAsOf18Jan2018 50d1fc6 [remotes/bitbucketFrmWin/master: 后面 5]
星號 * 是我本地分支的 HEAD 或我所在分支的提交。 通常它總是在尖端或頭部,即為什么它被稱為“頭部”
CurrAsOf18Jan2018 是我的本地主分支,重要的是它是說我的本地分支已經領先於我的遠程分支 5 次提交——它已經過時了,所以我需要用“git push”更新我的遠程分支
目前這只是這個故事的一方面。 如果您的遠程倉庫繼續進行,那么另一個工作流程將是
git fetch --all && git merge --ff-only <theCommitYouWantYouToCatchUpWith>
那完全是另一個帖子。
這是我發現的一個簡潔的圖像,由 Oliver Steele 提供,它顯示了版本控制的基本 git 工作流程生命周期的另一個版本
希望這會有所幫助。
git add .
git commit -m "my changes"
git remote add origin https://github.com/zinmyoswe/React-and-Django-Ecommerce.git
git push -u origin master
這個答案對我有用,我認為不需要添加遠程源,因為它已經在第一次將文件推送到存儲庫中時完成了。 要參考本地存儲庫更新 git 中心存儲庫:
git add .
git pull
git push -u origin main
git 添加。 git commit -m “消息” git 推送
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.