Git远程仓library
Git远程仓library is store in network on Git仓library, 用于团队协作 and codebackup. through远程仓library, many 个Development者可以共享 and 协作Development同一个project.
1. 常用 Git远程仓libraryservice
目 before has 许 many providingGit远程仓libraryservice 平台, 以 under is 最常用 几个:
1.1 GitHub
GitHub is 全球最 big Git远程仓library托管平台, 拥 has big 量open-sourceproject and 活跃 Development者community. 它providing了code托管, issues跟踪, CI/CDetc.丰富 functions.
1.2 GitLab
GitLab is a open-source Git仓librarymanagement平台, providing了code托管, CI/CD, containers仓libraryetc.functions. It supports自托管deployment, 适合企业 in 部using.
1.3 Gitee (码云)
Gitee is 国 in Git仓library托管平台, 访问速度 fast , 适合国 in Development者using. 它providing了code托管, code审查, CI/CDetc.functions.
1.4 Bitbucket
Bitbucket is Atlassian公司推出 Git仓library托管平台, and Jira, Confluenceetc.Atlassian产品集成良 good , 适合usingAtlassiantool链 团队.
2. clone远程仓library
using git clone commands可以将远程仓libraryclone to 本地, creation一个本地replica.
HTTPS vs SSH
- HTTPS: usinguser名 and password or 访问tokenforauthentication, 适合公共仓library or 临时using.
- SSH: usingSSHkeyforauthentication, 更security, 更方便, 适合 long 期using.
3. 关联远程仓library
such as果已经 has 了本地Git仓library, 可以using git remote add commands将其关联 to 远程仓library.
执行 git remote -v commands after , 你会看 to class似以 under 输出:
4. push本地branch to 远程仓library
using git push commands可以将本地branch submittingpush to 远程仓library.
关于 -u parameter
-u parameter用于将本地branch and 远程branch关联起来, 这样 after 续push时就可以直接using git push commands, 无需指定远程仓library and branch.
5. from 远程仓librarypullcode
using git pull commands可以 from 远程仓librarypull最 new code并merge to 本地branch.
5.1 git pull vs git fetch
git pull commands相当于 git fetch + git merge, 它会先 from 远程仓library获取最 new code, 然 after 自动merge to 本地branch.
而 git fetch commands只会 from 远程仓library获取最 new code, 但不会自动merge, 需要手动执行 git merge commandsformerge.
6. 查看远程仓libraryinformation
using git remote commands可以查看 and management远程仓library.
7. modify远程仓libraryURL
such as果远程仓library URL发生变化, 可以using git remote set-url commandsmodify本地关联 远程仓libraryURL.
8. delete远程仓library关联
using git remote remove commands可以delete本地 and 远程仓library 关联.
9. push本地tag to 远程仓library
using git push commands可以将本地tagpush to 远程仓library.
10. delete远程branch or tag
using git push commands可以delete远程branch or tag.
实践case: usingGitHubmanagementproject
- in GitHub on creation一个 new 仓library
- clone远程仓library to 本地:
git clone https://github.com/username/repository.git - 进入本地仓libraryTable of Contents:
cd repository - creation一个README.mdfile:
echo "# My Project" > README.md - submitting更改:
git add README.md && git submitting -m "Initial submitting" - push更改 to 远程仓library:
git push - in GitHub on 查看仓library, 确认更改已push成功
- in GitHub on modifyREADME.mdfile
- in 本地pull最 new 更改:
git pull - 查看本地file, 确认已pull to GitHub on modify
互动练习
请completion以 under 练习, 巩固Git远程仓libraryoperation:
- in GitHub/GitLab/Gitee on creation一个 new 远程仓library
- 将本地已 has Git仓library关联 to new creation 远程仓library
- push本地所 has branch and tag to 远程仓library
- using
git remote -v查看远程仓libraryinformation - clone刚刚creation 远程仓library to 另一个本地Table of Contents
- in clone 仓libraryinmodify一个file并submitting
- pushmodify to 远程仓library
- in 原本地仓libraryinpull最 new 更改
- creation一个 new 本地branch, submitting一些更改, 然 after push to 远程仓library
- delete远程仓libraryin testbranch
completion练习 after , 你应该able to熟练MasterGit远程仓library basicoperation!