# 将本地仓库推送到Github的流程
1.打开Git Bash,将当前目录更改为本地仓库
# 新建一个目录,将其初始化为Git代码库
$ git init [project-name]
1
2
2
2.在新的本地仓库中添加文件。 这会暂存它们用于第一次提交。
$ git add .
# Adds the files in the local repository and stages them for commit. 要取消暂存文件,请使用 'git reset HEAD YOUR-FILE'。
1
2
2
3.提交暂存在本地仓库中的文件。
$ git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote repository. 要删除此提交并修改文件,请使用 'git reset --soft HEAD~1' 并再次提交和添加文件。
1
2
2
4.在GitHub建立一个空的仓库,注意不要添加readme.md文件,防止后面报错!
5.在命令提示中,添加远程仓库的 URL (opens new window)(将在该 URL 推送本地仓库)。
$ git remote add origin [remote repository URL]
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
1
2
3
4
2
3
4
对应的如果远程分支创建错误可以使用
git remote rm或git remote remove命令删除远程URL$ git remote -v # 查看当前远程 > origin https://github.com/OWNER/REPOSITORY.git (fetch) > origin https://github.com/OWNER/REPOSITORY.git (push) > destination https://github.com/FORKER/REPOSITORY.git (fetch) > destination https://github.com/FORKER/REPOSITORY.git (push) $ git remote rm destination # 删除远程 $ git remote -v # 验证其已删除 > origin https://github.com/OWNER/REPOSITORY.git (fetch) > origin https://github.com/OWNER/REPOSITORY.git (push)1
2
3
4
5
6
7
8
9
10
11
12
13注:
git remote rm不会从服务器中删除远程仓库。 它只是从本地仓库中删除远程及其引用。**注**:`git remote rm` 不会从服务器中删除远程仓库。 它只是从本地仓库中删除远程及其引用。
6.推送更改(本地仓库中)到 GitHub。
$ git push origin master
# Pushes the changes in your local repository up to the remote repository you specified as the origin
1
2
2
# Git常用命令-易百教程 (opens new window)
# 一个本地分支对应多个远程分支
$ git remote set-url --add origin git@gitlab.com:fncheng/blog.git
$ git remote -v
origin git@github.com:fncheng/blog.git (fetch)
origin git@github.com:fncheng/blog.git (push)
origin git@gitlab.com:fncheng/blog.git (push)
1
2
3
4
5
2
3
4
5
表示执行git pull origin时从github拉取,git push origin时会把代码推送到github和gitlab