Git 远程操作
摘要:本文主要的内容包含,clone操作;建立本地仓库与remote之间的映射关系;fetch,pull,push的用法;远程分支的新建与删除.
1. clone
将原创仓库克隆至本地:
git clone <url> [<dest_file_name>]
2. remote
2.1 添加本地与远程的映射关系
利用 add remote 在本地增加远程快捷名称:
git add remote <remote_name> <url>
2.2 查看远程仓库信息
查看本地仓库包含的远程列表:
git remote -v
查看某远程仓库的详细信息:
git remote show <remote_name>
2.3 从远程仓库拉取修改
- 方法一:
先抓取修改,然后再合并到本地当前分支:
git fetch <remote_name> <branch_name>:<local_branch_name>
git merge <local_branch_name>
- 方法二:
直接一步执行拉取+合并至本地当前分支:
git pull <remote_name> <branch_name>
还可以拉取合并到本地指定分支,或者本地的新建分支:
git pull <remote_name> <branch_name>:<local_branch_name>
2.4 将本地修改推送到远程仓库
将本地的 branch_name 分支推送到远程的同名分支:
git push <remote_name> <branch_name>
将本地的 local_branch_name 分支,推送到远程的 branch_name 分支:
git pull <remote_name> <local_branch_name>:<branch_name>
2.5 新建与删除远程分支
- 新建远程分支:
在向远程推送本地更改,如果指定的推送目标分支不存在,就会在远程新建一个分支; - 删除远程分支:
git push <remote> --delete <branch_name>