将本地代码提交到Github

本文详细介绍如何将本地代码仓库提交到GitHub。包括创建新仓库并首次提交、推送已有仓库至GitHub及从其他仓库导入代码的方法。

【时间】2019.12.13

【题目】将本地代码提交到Github

具体参考:Git 远程仓库(Github)

在Github上创建仓库后,使用以下命令:

一、...or create a new repository on the command line

在本地创建新的代码仓库,并提交到Github仓库。

echo "# PyramidNet-Keras" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/1490581824/PyramidNet-Keras.git
git push -u origin master

二、…or push an existing repository from the command line

将已有的仓库推送(push)到Github上。

git remote add origin https://github.com/1490581824/PyramidNet-Keras.git
git push -u origin master

三、…or import code from another repository

从其他Github仓库导入。

You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

Import code

本地代码提交GitHub 一般可以按照以下步骤进行: ### 1. 创建 GitHub 仓库 首先登录 GitHub 账号,点击右上角的 “+” 号,选择 “New repository”。在打开的页面中填写仓库名称、描述等信息,选择仓库的公开或私有属性,然后点击 “Create repository” 完成创建。 ### 2. 本地安装并配置 Git 如果尚未安装 Git,需要先从 [Git 官方网站](https://git-scm.com/downloads) 下载并安装适合自己操作系统的版本。安装完成后,在本地命令行中配置个人信息,命令如下: ```bash git config --global user.name "Your Name" git config --global user.email "your_email@example.com" ``` ### 3. 初始化本地仓库 打开命令行工具,进入本地代码所在的目录,使用以下命令初始化一个新的 Git 仓库: ```bash git init ``` ### 4. 添加文件到暂存区 使用以下命令将本地代码文件添加到 Git 的暂存区: ```bash git add . ``` 这里的 “.” 表示添加当前目录下的所有文件。如果只想添加特定文件,可以将 “.” 替换为文件名。 ### 5. 提交本地仓库 将暂存区的文件提交本地 Git 仓库,并添加提交说明: ```bash git commit -m "Initial commit" ``` “Initial commit” 是本次提交的说明信息,可以根据实际情况进行修改。 ### 6. 关联远程仓库 将本地仓库与之前在 GitHub 上创建的远程仓库进行关联,使用以下命令: ```bash git remote add origin https://github.com/your_username/your_repository.git ``` 将 “your_username” 替换为你的 GitHub 用户名,“your_repository” 替换为你创建的仓库名称。 ### 7. 推送代码GitHub 最后,使用以下命令将本地仓库的代码推送到 GitHub 上: ```bash git push -u origin master ``` 如果你的分支名不是 “master”,需要将 “master” 替换为实际的分支名。首次推送时使用 “-u” 参数会将本地分支与远程分支进行关联,之后推送可以直接使用 `git push` 命令。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值