git 如何开始在本地和 Github 上使用我的存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5437521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I start using my repository locally and on Github?
提问by MEM
So:
所以:
1) I have created my account on github and I've created a repository there.
1) 我在 github 上创建了我的帐户,并在那里创建了一个存储库。
2) I have the keys to access the repository from my dev machine to github, using SSH, so that my local repository is synchronized with the remote one hosted on github once I do, push or pull.
2) 我拥有使用 SSH 从我的开发机器访问存储库到 github 的密钥,以便我的本地存储库与托管在 github 上的远程存储库同步,一旦我执行,推送或拉取。
But, I'm not understanding how will all this start.
但是,我不明白这一切将如何开始。
I have my local files on this dev computer and from there I do:
我在这台开发计算机上有我的本地文件,然后我做:
3) git init
3) git 初始化
then
然后
4) git add
4) git 添加
and then I 5) commit that project to my LOCAL repository.
然后我 5) 将该项目提交到我的本地存储库。
Once this is done, then I will 6) push this to github repository.
完成后,我将 6) 将其推送到 github 存储库。
Is this correct?
这样对吗?
回答by vcsjones
That's basically correct, yes. To explain what each thing is doing...
这基本上是正确的,是的。解释每件事在做什么......
git init
basically says, "Hey, I want a repository here." You only will have to do this once per repository.- After that, you will want to add a remote, which GitHub probably told you to do by using
git remote add origin [email protected]:username/repository
This allows you to push to a remote. You will only have to do this once as well. - After that, use
git add
to add your changes, or "stage them". You can usegit add -i
for a bit of a more interactive experience. - Use
git commit -m 'message'
to commit locally. - Then use
git push origin master
This says, "Push all of the commits to the remote origin, under master. - If you make changes from another machine, or someone else makes changes, you can use
git pull
to get them from the remote.
git init
基本上是说,“嘿,我想要一个这里的存储库。” 您只需为每个存储库执行一次此操作。- 之后,您将需要添加一个遥控器,GitHub 可能告诉您通过使用
git remote add origin [email protected]:username/repository
This 允许您推送到遥控器。您也只需执行一次此操作。 - 之后,用于
git add
添加您的更改,或“暂存”。您可以使用git add -i
一些更具交互性的体验。 - 用于
git commit -m 'message'
在本地提交。 - 然后使用
git push origin master
This 说,“将所有提交推送到 master 下的远程源。 - 如果您从另一台机器进行更改,或者其他人进行了更改,您可以使用
git pull
来从远程获取它们。
You might want to consider reading ProGit- it's free online and is a wealth of information. There you can learn more about features like branching, merging, etc.
您可能需要考虑阅读ProGit- 它是免费在线的,而且信息丰富。在那里您可以了解有关分支、合并等功能的更多信息。
回答by Rafe Kettler
You're missing one step: somewhere before the last step, you need to do a git remote add origin [email protected]:username/reponame
so that Git knows where to push your repo when you say git push origin master
. Otherwise, you've got it! You may want to check your work with git diff
before you commit, though.
您错过了一步:在最后一步之前的某个地方,您需要执行 agit remote add origin [email protected]:username/reponame
以便 Git 在您说git push origin master
. 否则,你已经得到了!不过,您可能希望git diff
在提交之前检查您的工作。
回答by Laur
I think you only need to do an: git push origin master
you can find details here: http://programertools.blogspot.com/2014/04/how-to-use-github.html
我认为你只需要做一个:git push origin master
你可以在这里找到详细信息:http: //programertools.blogspot.com/2014/04/how-to-use-github.html