git 如何在github上传新代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2866872/
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 can I upload fresh code at github?
提问by Lazer
I have a directory with all my coding projects.
我有一个包含我所有编码项目的目录。
I want to upload (correct terminology?) it to GitHubusing the command line.
我想使用命令行将它上传(正确的术语?)到GitHub。
I have already looked at Old question.
我已经看过老问题了。
I know how to clone an existing project, and how to push it after making any changes.
我知道如何克隆现有项目,以及如何在进行任何更改后推送它。
But in this case, I want to make a new project and add files to that.
但在这种情况下,我想创建一个新项目并向其中添加文件。
How can I accomplish this using the command line?
如何使用命令行完成此操作?
采纳答案by Veeti
git init
git add .
git commit -m "Initial commit"
After this, make a new GitHub repository and follow on-screen instructions.
在此之后,创建一个新的 GitHub 存储库并按照屏幕上的说明进行操作。
回答by Rob Wilkerson
If you haven't already created the project in Github, do so on that site. If memory serves, they display a page that tells you exactly how to get your existing code into your new repository. At the risk of oversimplification, though, you'd follow Veeti's instructions, then:
如果您尚未在 Github 中创建项目,请在该站点上创建。如果没记错的话,它们会显示一个页面,告诉您如何将现有代码放入新存储库。但是,冒着过于简单化的风险,您可以按照 Veeti 的说明进行操作,然后:
git remote add [name to use for remote] [private URI] # associate your local repository to the remote
git push [name of remote] master # push your repository to the remote
回答by mrmoje
Just to add on to the other answers, before i knew my way around git, i was looking for some way to upload existing codeto a new github (or other git) repo. Here's the brief that would save time for newbs:-
只是为了补充其他答案,在我了解 git 之前,我正在寻找某种方法将现有代码上传到新的 github(或其他 git)存储库。这是为新手节省时间的简介:-
Assuming you have your NEW empty github or other git repo ready:-
假设您准备好新的空 github 或其他 git repo:-
cd "/your/repo/dir"
git clone https://github.com/user_AKA_you/repoName # (creates /your/repo/dir/repoName)
cp "/all/your/existing/code/*" "/your/repo/dir/repoName/"
git add -A
git commit -m "initial commit"
git push origin master
Alternatively if you have an existing local git repo
或者,如果您有一个现有的本地 git 仓库
cd "/your/repo/dir/repoName"
#add your remote github or other git repo
git remote set-url origin https://github.com/user_AKA_you/your_repoName
git commit -m "new origin commit"
git push origin master
回答by ddewaele
You can create GitHub repositories via the command line using their Repositories API (http://develop.github.com/p/repo.html)
您可以使用他们的 Repositories API ( http://develop.github.com/p/repo.html)通过命令行创建 GitHub 存储库
Check Creating github repositories with command line | Do it yourself Androidfor example usage.
回答by Matt
It seems like Github has changed their layout since you posted this question. I just created a repository and it used to give you instructions on screen. It appears they have changed that approach.
自从您发布此问题以来,Github 似乎已更改其布局。我刚刚创建了一个存储库,它曾经在屏幕上为您提供说明。看来他们已经改变了这种方法。
Here is the information they used to give on repo creation:
以下是他们用于提供有关 repo 创建的信息:
回答by Sanjay Bhalani
In Linux use below command to upload code in git
1 ) git clone repository
ask for user name and password.
2) got to respositiory directory.
3) git add project name.
4) git commit -m ' messgage '.
5) git push origin master.
- user name ,password
在 Linux 中使用以下命令在 git 中上传代码
1 ) git clone 存储库
询问用户名和密码。
2) 到 respositiory 目录。
3) git 添加项目名称。
4) git commit -m '消息'。
5) git push origin master。
- 用户名密码
Update new Change code into Github
将新的更改代码更新到 Github
->Goto Directory That your github up code
->git commit ProjectName -m 'Message'
->git push origin master.
->Goto Directory 你的 github up 代码
->git commit ProjectName -m 'Message'
->git push origin master。
回答by WesternGun
From Github guide: Getting your project to Github:(using Github desktop version)
来自Github 指南:将您的项目带到 Github:(使用 Github 桌面版)
Set up your project in GitHub Desktop
The easiest way to get your project into GitHub Desktop is to drag the folder which contains your project files onto the main application screen.
If you are dragging in an existing Git repository, you can skip ahead and push your code to GitHub.com.
If the folder isn't a Git repository yet, GitHub Desktop will prompt you to turn it into a repository. Turning your project into a Git repository won't delete or ruin the files in your folder—it will simply create some hidden files that allow Git to do its magic.
在 GitHub Desktop 中设置您的项目
将项目放入 GitHub Desktop 的最简单方法是将包含项目文件的文件夹拖到主应用程序屏幕上。
如果您正在拖入现有的 Git 存储库,您可以跳过并将您的代码推送到 GitHub.com。
如果该文件夹还不是 Git 存储库,GitHub Desktop 会提示您将其转换为存储库。将您的项目转换为 Git 存储库不会删除或破坏文件夹中的文件——它只会创建一些隐藏文件,让 Git 发挥其魔力。
In Windows it looks like this:(GitHub desktop 3.0.5.2)
在 Windows 中它看起来像这样:(GitHub 桌面 3.0.5.2)
this is not the most geeky way but it works.
这不是最令人讨厌的方式,但它有效。