git远程仓库使用

git远程仓库使用

   张吉吉     2020年6月12日 07:20     1683    

使用远程仓库有三种情况

 

第一种从远程仓库建立新项目

从远程克隆仓库到本地

在远程仓库种建立项目,github或者自建的gitlab都有图形界面,从其建立即可。

克隆远程项目到本地

git clone http://URL:PORT/account_name/test.git

cd test

touch README.md

git add README.md

提交创建的文件

git commit -m "add README"

将本地文件推送到远程仓库,默认的名称就是origin

git push -u origin master

 

第二种从本地新建项目

建立并初始化git仓库

cd test

git init

登陆远程仓库,然后添加远程仓库,origin是可以自定义的。

git remote add origin http://URL:PORT/account_name/test.git

git add .

git commit -m "Initial commit"

git push -r origin master

 

第三种远程克隆已经有的项目

cd existing_repo

git clone http://URL:PORT/account_name/test.git

git remote add origin http://URL:PORT/account_name/test.git

git push -u origin --all

git push -u origin --tags

 

查看远程仓库

git remote –v

1.png


修改远程仓库的地址

方式1、直接修改:

git remote set-url origin xxxxx.git

方式2、先删后加 :

git remote rm origin
git remote add origin xxxxx.git

修改默认pull和push分支:

git branch --set-upstream-to=origin/develop develop
origin/develop develop为要设置的默认分支


文章评论

0

其他文章