git push 本地项目推送到远程分支[z]

大家有的时候,会在本地新建项目,这里说一下在本地项目建立本地git仓库,然后push到远程仓库的步骤

1.在本地项目的文件夹下,git仓库初始化

git init

  初始化本地git仓库 

 

2.

git add * 

将本地文件索引添加至git库中

3.

git commit -m "first" 
# -m 后为提交日志

4.

git branch

可查看本地仓库分支,发现会出现一个master的分支

5.配置远程仓库

git remote add test http://xxxx@git.XXXX.com/scm/wbqa/xxxx.git
# test 为远程仓库别名 后面http 为远程仓库地址

6.配置完成后,可使用 git remote -v 命令查看是否生效

7.使用push命令,将代码提交到远程对应分支

$ git push <远程主机名> <本地分支名>:<远程分支名>

git push test master:jenkinsapi

#test 为设置的远程仓库别名,master为本地分支名,jenkinsapi为远程分支名

若没有配置远程仓库用户名与密码,push代码时会让输入用户名与密码,成功后将会出现如下信息,可使用git config 命令配置

复制代码
Counting objects: 20, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (20/20), 2.63 MiB | 6.97 MiB/s, done.
Total 20 (delta 0), reused 0 (delta 0)
remote: 
remote: Create pull request for jenkinsapi:
remote:   http://git.xxxxxxx.com/projects/WBQA/repos/xxxxxxx_api_xxxx_api_case/compare/commits?sourceBranch=refs/heads/jenkinsapi
remote: To http://git.xxxxxxx.com/scm/wbqa/xxxxxxx_api_xxxxx_api_case.git
 * [new branch]      master -> jenkinsapi
复制代码

8.此时查看远程仓库,会发现多了一个以jenkinsapi 命名的分支

注:git命令的详细解析将不此列出,请自行百度、谷歌

原文地址:https://www.cnblogs.com/jjj250/p/10937949.html