将现有源代码导入GitHub [英] Import existing source code to GitHub
问题描述
如何将源代码从我的电脑导入到我的GitHub帐户?
如果您有本地源代码你想添加到一个新的远程新的git仓库而不用'克隆'远程,首先执行以下操作(我经常这样做 - 你在bitbucket / github中创建远程空仓库,然后推送你的源代码)
-
创建远程存储库,并获取诸如
git@github.com:/youruser/somename.git
或https://github.com/youruser/somename.git
如果您已经设置了本地GIT仓库,跳过步骤2和步骤3
,在你的源代码根目录下,git init
2a。如果您使用.gitignore和README.md初始化回购库,则应该执行
git pull {步骤1中的url}
,以确保您不会提交源文件你想忽略;)
-
在本地,添加并提交你想要的东西在你的初始回购(任何东西,
git add。
/ code>然后 -
将您的远程仓库与名称'origin'相关联(如克隆会执行的操作)
git remote add origin [URL From Step 1]
- 执行
git pull origin master
来拉远程分支,使它们同步。
- 推高主分支(将主分支更改为其他分支的其他分支):
git push origin master $> c $ c>
git commit -m'初始提交评论'
) $ b
How can I import source code from my computer to my GitHub account?
If you've got local source code you want to add to a new remote new git repository without 'cloning' the remote first, do the following (I often do this - you create your remote empty repository in bitbucket/github, then push up your source)
Create the remote repository, and get the URL such as
git@github.com:/youruser/somename.git
orhttps://github.com/youruser/somename.git
If your local GIT repo is already set up, skips steps 2 and 3
Locally, at the root directory of your source,
git init
2a. If you initialize the repo with a .gitignore and a README.md you should do a
git pull {url from step 1}
to ensure you don't commit files to source that you want to ignore ;)Locally, add and commit what you want in your initial repo (for everything,
git add .
thengit commit -m 'initial commit comment'
)to attach your remote repo with the name 'origin' (like cloning would do)
git remote add origin [URL From Step 1]
- Execute
git pull origin master
to pull the remote branch so that they are in sync. - to push up your master branch (change master to something else for a different branch):
git push origin master
这篇关于将现有源代码导入GitHub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!