2014-12-25 42 views
0

我對github很新,想知道如何將本地項目推送或設置到遠程環境?例如,我在C:\ project中有一個項目,如何將它發送給github remote?使用git控制檯時我一直失敗。任何步驟?如何將本地git項目設置爲遠程?

+0

'我在使用git console時失敗了'如果你用控制檯解釋你正在嘗試的內容,它可能會有所幫助 – gturri

回答

3

步驟使用:

create a local repository, if not yet, 
commit local repository locally, 
     git add . 
     git commit -am "init" 
create a repository on github with same name as local repo: 
     left it empty, no README or .gitignore file, 
config remote: 
     git remote add origin https://github.com/[user]/[project_name].git 

set remote url: 
     git config remote.origin.url https://[user]@github.com/[user]/[project_name] 

initial push to github: 
     git push -u origin master 

set tracking info - master: 
     git branch --set-upstream-to origin/master 
     tip: 
      before do this, the remote repo should at least contain 1 commit, 
      you can do this by push once, or create a file remotely (e.g. README.md). 

check the project on github, to see is it ok. 

如果你有多個本地分支,你想跟蹤多個分支github上,不只是主人。

steps - push another branch to github: 
* make sure both local/remote have the same branch already, 
     if not yet, you can push a local branch to remote first, 
     format: 
      git push [remote] [branch] 
* in local 
     switch to specific branch, 
     then set its upstream via: 
      git branch --set-upstream-to=<remote>/<remote_branch> <local_branch> 
     e.g. 
      git branch --set-upstream-to=origin/develop develop 
* 

學習的地方混帳

1

如果你當前的工作文件夾沒有被Github的初始化,然後使用以下命令:

git init 
git remote add origin <the http git address of your remote repository> 
git add . 
git commit -m "<some comments for this commit>" 
git push origin master 

如果您的工作副本已初始化,並且您想要將遠程目標存儲庫更改爲另一個。然後,我相信下面的命令將幫助:

git remote set-url origin <the address of your new repository> 
git add . 
git commit -m "<some comments>" 
git push origin <the branch you want to push to> 

希望這個答案是非常有用的!