赞
踩
进入到仓库文件夹使用git init进行初始化
cd Git
git init
origin为远程仓库起的别名,URL为远程仓库的链接
$ git remote add origin <URL>
git fetch origin master 为拉取远程仓库master分支
git fetch origin 可以获取远程仓库全部分支
如果只在项目的一个分支上操作拉取单个分支就可以
样例为拉取全部分支
$ git fetch origin
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
git branch -r
origin/master
origin/test
git checkout -b mytest origin/test
Branch mytest set up to track remote branch test from origin.
Switched to a new branch 'mytest'
$ git branch
* mytest
$ git branch --set-upstream-to=origin/test mytest
Branch mytest set up to track remote branch test from origin.
//查看绑定的远程分支
$ git branch -vv
* mytest e8e7d01 [origin/test: ahead 1] First Revision
//查看已拉取的远端文件
$ ls
main
$ git add test.cpp
$ git commit -m "First Revision"
[mytest e8e7d01] First Revision
1 file changed, 1 insertion(+), 2 deletions(-)
使用git pull 可以同步远端最新的文件信息,加上–rebase参数可以使上传的分支变成一条直线,使项目更改的流程看起来更加清晰
$ git pull --rebase
Current branch mytest is up to date.
如果git pull提示有文件未跟踪可以通过git stash 直接保存未提交更改,或者git stash save “添加描述”进行保存。
pull之后使用 git stash pop 恢复原来的文件并删除stash。
因为本地分支mytest与远程分支test名称不一样,需要进行指定
$git push origin mytest:test
Counting objects: 11, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 617 bytes | 0 bytes/s, done.
Total 8 (delta 1), reused 0 (delta 0)
remote:
remote: To create a merge request for test, visit:
remote: http://192.168.2.114/JinJieC/myObjectTest/merge_requests/new?merge_request%5Bsource_branch%5D=test
remote:
To git@192.168.2.114:JinJieC/myObjectTest.git
ddd077e..73083c5 mytest -> test
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。