2010-05-19 44 views
96

我有一個包含我所有編碼項目的目錄。如何在github上傳新鮮的代碼?

我想使用命令行上傳(正確的術語?)到GitHub。我已經看過Old question

我知道如何克隆現有項目,以及如何在做出任何更改後推送它。

但在這種情況下,我想創建一個新項目並添加文件。

如何使用命令行來完成此操作?

回答

79
git init 
git add . 
git commit -m "Initial commit" 

在此之後,創建一個新的GitHub存儲庫並按照屏幕上的說明操作。

+0

因此,只有使用GitHub的圖形用戶界面,而不是通過命令行庫將非常具有創造出來的? – Lazer 2010-05-19 15:31:54

+8

@eSKay:你首先必須有一個本地回購,然後添加一個遙控器,並推送到該遙控器。所有這些都是從命令行完成的。推動github有一些先決條件,比如在github上創建一個項目並添加ssh密鑰來標識自己。 – hasen 2010-05-19 16:12:55

+0

這沒有奏效。我得到的混帳推-u起源掌握以下錯誤信息:「錯誤:未能一些裁判推到‘[email protected]:XXXX/yyyy.git’ 爲了防止丟失歷史,非快進更新被拒絕 再次前推合併遠程修改。請參閱「備註 快進」,瞭解詳情「混帳推--help」的部分。」 – chmike 2012-05-20 13:56:12

28

如果您還沒有在Github中創建項目,請在該站點上執行此操作。如果內存提供服務,它們將顯示一個頁面,告訴您如何將現有代碼存入新的存儲庫。在過於簡單化的風險,不過,你會遵循Veeti的指令,則:

git remote add [name to use for remote] [private URI] # associate your local repository to the remote 
git push [name of remote] master # push your repository to the remote 
+2

如果用戶爲其存儲庫創建了自述文件,我建議首先執行「拉」操作,否則他們將不得不進行合併。 – knownasilya 2012-12-26 23:26:40

+1

不,剛剛創建了一個回購協議,它給**的下一步該怎麼做 – puk 2013-12-09 19:55:46

+0

@puk不知道你在哪裏,或者你看到的,但是當我創建Github上一個新的回購協議,我看到一個完全沒有**的說明非常明確的一套指示。 1設置爲「在命令行上創建新的存儲庫」,另一個設置爲「從命令行推送現有存儲庫」,另一個設置爲使用Github桌面應用程序。 – 2013-12-12 17:05:48

3

自從您發佈此問題以來,Github似乎已經更改了它們的佈局。我剛剛創建了一個存儲庫,它用來在屏幕上給你說明。看來他們已經改變了這種做法。

這裏是他們用來給上回購創造的信息:

Create A Repo · GitHub Help

21

只是爲了添加到其他的答案,我知道我身邊的git的方式之前,我一直在尋找一些方法來上傳現有的代碼到一個新的github(或其他git)回購。下面是可以節省時間newbs簡要: -

假設你有你的新的空github上或其他的git回購準備: -

cd "/your/repo/dir" 
git clone https://github.com/user_AKA_you/repoName # (creates /your/repo/dir/repoName) 
cp "/all/your/existing/code/*" "/your/repo/dir/repoName/" 
git add -A 
git commit -m "initial commit" 
git push origin master 

或者,如果你有一個現有的本地git倉庫

cd "/your/repo/dir/repoName" 
#add your remote github or other git repo 
git remote set-url origin https://github.com/user_AKA_you/your_repoName 
git commit -m "new origin commit" 
git push origin master 
-1

Github guide: Getting your project to Github:(使用Github的桌面版)

Set up your project in GitHub Desktop

The easiest way to get your project into GitHub Desktop is to drag the folder which contains your project files onto the main application screen.

If you are dragging in an existing Git repository, you can skip ahead and push your code to GitHub.com.

If the folder isn’t a Git repository yet, GitHub Desktop will prompt you to turn it into a repository. Turning your project into a Git repository won’t delete or ruin the files in your folder—it will simply create some hidden files that allow Git to do its magic.

enter image description here

在Windows中,它看起來是這樣的:(GitHub的桌面3.0.5.2)

enter image description here

這是不是最古怪的方式,但它的工作原理。

1

在Linux中使用以下命令在Git中
1)的git克隆庫
上傳代碼詢問用戶名和密碼。
2)進入respositiory目錄。
3)git添加項目名稱。
4)git commit -m'messgage'。
5)git push origin master。
- 用戶名,密碼

更新新的變化的代碼到Github上

- >轉到目錄您的GitHub代碼最多
- > git的承諾項目名-m '消息'
- >混帳推起源主。

相關問題