如何用git将项目代码上传到github

责编:menVScode 2019-05-21 0:02 阅读(502)

1. 在github创建(New repository )一个新的仓库。



2. 下载并安装git客户端


3. git初始化,执行【git init】命令

$ git init
Initialized empty Git repository in D:/wzc/code/bigstudent-web2/.git/


4. 为了把本地的仓库传到github,还需要本地配置ssh key

$ ssh-keygen -t rsa -C "邮箱账号@youremail.com"

操作如下:

$ ssh-keygen -t rsa -C "third@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/wzc00/.ssh/id_rsa):

直接回车,会在默认文件id_rsa上生成ssh key

Created directory '/c/Users/wzc00/.ssh'.

然后系统要求输入密码,直接按回车表示不设密码,重复密码也是回车。

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/wzc00/.ssh/id_rsa.
Your public key has been saved in /c/Users/wzc00/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:eLi049mCYFkULdCG/DUm01HSrZcryxNHnrZaOnBf6Yc third_king@163.com
The key's randomart image is:
+---[RSA 2048]----+
| ..+.+o+..       |
|  o B *.. .      |
|   + * . . .     |
|    o  o. +      |
|   o  + S+ o .   |
|  +  ..++ * o    |
| . . .++ B.+ .   |
|    ...+=oo E .  |
|      o.++   .   |
+----[SHA256]-----+

提示你在这个(/c/Users/wzc00/.ssh/)目录下已经成功生成 shh key 文件。


5. 记事本打开 id_rsa.pub 文件,复制其中的内容;回到回到github网站,进入【头像】->【Setting】->【SSH and GPG keys】->【SSH keys】


点击【New SSH Key】,将内容复制进去,最后保存。

验证是否成功,在git bash下输入:

$ ssh -T git@github.com

回车后显示: You've successfully authenticated, but GitHub does not provide shell access,这就表示已成功连上github。

$ ssh -T git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,131.230.107.213' (RSA) to the list of known hosts.
Hi THIRDKING! You've successfully authenticated, but GitHub does not provide shell access


6. 设置username和email,把本地仓库传到github上去,可以让github每次commit都会记录他们。

wzc00@MSI MINGW64 /d/wzc/code/bigstudent-web2 (master)
$ git config --global user.name "mvc003"

wzc00@MSI MINGW64 /d/wzc/code/bigstudent-web2 (master)
$ git config --global user.email "third@163.com"


7. 进入要上传的仓库,添加远程地址

$ git remote add origin git@github.com:THIRDKING/bigstudent-web2.git



8. 到这一步就能提交我们的代码到github上了,常用的命令如下所示:

git add .
 
git commit -m "img commit"
 
$ git pull
 
$ git push -u origin master

===================================

…or create a new repository on the command line

git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:THIRDKING/51fanbei-web.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin git@github.com:THIRDKING/51fanbei-web.git
git push -u origin master
标签: github
前端交流群: MVC前端网(menvscode.com)-qq交流群:551903636

邮箱快速注册

忘记密码