2014-12-25 27 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> 

希望这个答案是非常有用的!