Git 远程仓库使用记录

1. 关联远程项目

git remote add origin <remote_url>
  • remote_url:远程仓库地址,通常为 xxx/xxx.git

示例:
git remote add origin git@github.com:bykevin/Linux_base.git


2. 关联远程分支和本地分支

关联远程项目后 pull 或者 push 时,可能会报以下错误:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.


git pull <remote><branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> release
git branch --set-upstream-to origin/develop

可以使用以下命令关联远程分支和本地分支:

git branch --set-upstream-to=<origin/remote_branch>  [your_branch]
  • origin/remote_branch:要关联的远程分支
  • your_branch:关联的本地分支,不填写时默认为当前分支。

3. 保留远程用户名和密码

每次 pull 或 push 时都会提示输入用户名和密码,如果想在本地保存用户名和密码可以使用以下命令。使用后再输入一次后,权限信息就保留下来了。

git config  credential.helper store               
  • 可以加上 --global 配置成全局用户名和密码

4. 删除与远程关联

取消本地仓库与远程仓库的关联。

git remote remove origin

5. 删除提交到远程仓库的文件

有时候会将不是源文件的一些项目文件、编译文件等上传到远程仓库,例如 .idea 文件夹。

修改 .gitignore

在文件中添加不在 trace 的文件或目录。

例如:
/.idea/

删除不再跟踪的文件(本地目录中保留)

git rm -r --cached <file or directory>
  • -r :递归删除文件或目录
  • –cached:从暂存区删除,不在 trace 文件或目录
  • file or directory:要删除的文件或目录

完成这一步后, 重新提交并 push 到远程分支。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值