2017-08-10 164 views
0

我经常想要做到这一点,但永远不会记得如何。GIT:同步本地文件到新的github版本库

首先我在我的电脑上创建一个文件,一些源代码,现在我想把它推到github仓库。

所以我创建了一个github回购。 (在github上)点击“克隆”以获取更高版本的URL。

现在我在本地机器上运行以下命令。

git init // make a repo, local 
git add * // add files to repo 
git commit -a -m "initial commit" // commit files to repo and add msg 
git remote add origin (...url...) // tell git where to push 
git push --set-upstream origin master // no idea what this does 
git config --global user.name "...name..." // set my name so github knows what my username is 
git push // does not work error: 

To push the current branch and set the remote as upstream, use 

    git push --set-upstream origin master 

还是不能“推”。我究竟做错了什么?

+0

可能重复[默认行为的“git推”没有指定分支](https://stackoverflow.com/questions/) 948354/default-behavior-of-git-push-without-a-branch-specified) – phd

+0

您的问题中的代码块是否是您实际运行的命令的日志?因为如果你在运行'git remote add origin '命令后运行'git push --set-upstream origin master',它应该适合你。 – instantepiphany

回答

0

尝试克隆,然后cd进入回购。之后,add *。然后运行你想要的提交并推送。这应该工作。如果我这样做没有任何分支,它会看起来像这样:

> git clone 'repoName' 
> cd repoName 
> git add * 
> git commit -m "first commit" 
> git push 
+0

我以为git克隆会擦除我的本地文件? – user3728501

+0

克隆回购,然后将代码从您的计算机移动到该回购。另外,请始终记得保存备份! – Jsleshem