您的位置:首页 > 其它

Git创建分支并推送到服务器具体步骤

2017-08-15 14:07 337 查看
Last login: Thursday 2017-08-03 15:36:00

切换到要同步的目录下面

cd /Desktop/project
初始化git
git init
查看本地分支:
git branch -a
* master

创建本地新分支:

git branch develop
切换到本地新建的分支:
git checkout develop
查看本地分支:
git branch -a
添加文件本地暂存空间
git add .
提交到本地仓库
git commit -m 'develop branch'

尝试推送到远程仓库失败:没有创建SSH密钥

git push git@xx.xx.xx.xxx:xxx/xxxx develop:develop
The authenticity of host '<serverIP> (<ServerIP>)' can't be established.
ECDSA key fingerprint is SHA256:4iz8GeaeyVQwOUosf95NgKC/TnZEltJNdTM0F6Bx1ko.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'serverIP' (xxx) to the list of known hosts.
git@gitserverIP's password: 
Permission denied, please try again.

创建本地密钥:

ssh-keygen -t rsa -C "sample@email.com"
Generating public/private rsa key pair.
Enter file in which to save the key
(/Users/xxx/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/xxx/.ssh/id_rsa.
Your public key has been saved in /Users/xxx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/xGIikiH0MzxNeyXj2g61mJTmGeKYMFvc481o9Frkjs
sample@email.com
The key's randomart image is:
+---[RSA 2048]----+
|  .  .o          |
| + o ...         |
|o + ..   .       |
| + .  . o. .     |
|  = .o.oSo. .    |
|.o *o+**...  .   |
|..o.+OO + . .    |
|  . OE.+   . .   |
|   o ==     .    |
+----[SHA256]-----+
MacBook-Air:xxx xxx$ open ~/.ssh/
直接在文件夹里用文本编辑打开文件:id_rsa.pub
将里面的内容粘贴在服务器上的SSH key里面命名key的名字并点击添加
检查是否添加成功:
ssh -T git@<gitServerIP>
显示下面的信息就表示成功了:Welcome to Git, Sample!
下面的配置,一次配置完后面不用每次输入用户名密码:
git config --global user.name "xxx"
git config --global user.email "[b]sample@email.com[b]"[/b][/b]

再次尝试推送本地仓库的分支到远程仓库:

git push git@<gitServerIP>:<group>/<project> develop:develop
Counting objects: 267, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (259/259), done.
Writing objects: 100% (267/267), 43.50 MiB | 13.74 MiB/s, done.
Total 267 (delta 149), reused 0
(delta 0)
remote: Resolving deltas: 100% (149/149), done.
remote: 
remote: To create a merge request for develop, visit:
remote:   http://gitServerIP/group/projectname/merge_requests/new?merge_request%5Bsource_branch%5D=develop remote: 
To gitserverIP:group/project
 * [new branch]     
develop -> develop
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: