git 远程操作(五)

Posted on Posted in git
  • git clone
  • git fetch #获取远程仓库的所有分支以及数据
  • git pull #其实是 git fetch 和 git merge 的一个组合操作
  • git push

git clone 支持的协议

ssh/git/http/https/ftp/ftps/rsync

git 远程操作

-> dreamoon@lhh-mac ~/git ☺ git clone https://github.com/liuhonghe/test.git  
-> dreamoon@lhh-mac ~/git ☺ cd test  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git fetch  
remote: Counting objects: 3, done.  
remote: Compressing objects: 100% (2/2), done.  
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0  
Unpacking objects: 100% (3/3), done.  
From https://github.com/liuhonghe/test  
   9210f41..b23af75  master     -> origin/master  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git log --oneline --decorate --graph --all  
* b23af75 (origin/master, origin/HEAD) Create test.txt  
* 9210f41 (HEAD -> master) Update README.md  
* eede676 Initial commit  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git merge origin/master  
Updating 9210f41..b23af75  
Fast-forward  
 test.txt | 1 +  
 1 file changed, 1 insertion(+)  
 create mode 100644 test.txt  
-> dreamoon@lhh-mac ~/git/test git:(master) ✗ 1☺ git add test.txt  
-> dreamoon@lhh-mac ~/git/test git:(master) ✗ ☺ git commit -m "add some local"  
[master 2d8a0bf] add some local  
 1 file changed, 1 insertion(+)  
# 假设远程上已经有人更新了文件  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git push  
Password for 'https://liuhonghe@github.com':  
To https://liuhonghe@github.com/liuhonghe/test.git  
 ! [rejected]        master -> master (fetch first)  
error: failed to push some refs to 'https://liuhonghe@github.com/liuhonghe/test.git'  
hint: Updates were rejected because the remote contains work that you do  
hint: not have locally. This is usually caused by another repository pushing  
hint: to the same ref. You may want to first integrate the remote changes  
hint: (e.g., 'git pull ...') before pushing again.  
hint: See the 'Note about fast-forwards' in 'git push --help' for details.  
-> dreamoon@lhh-mac ~/git/test git:(master) 1☺ git pull  
remote: Counting objects: 3, done.  
remote: Compressing objects: 100% (2/2), done.  
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0  
Unpacking objects: 100% (3/3), done.  
From https://github.com/liuhonghe/test  
   b23af75..be08923  master     -> origin/master  
Auto-merging test.txt  
CONFLICT (content): Merge conflict in test.txt  
Automatic merge failed; fix conflicts and then commit the result.  
-> dreamoon@lhh-mac ~/git/test git:(master) 1☺ vim test.txt #解决冲突  
-> dreamoon@lhh-mac ~/git/test git:(master) 1☺ git add test.txt  
-> dreamoon@lhh-mac ~/git/test git:(master) 1☺ git commit  # 本地的历史是最新的  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git push  
Password for 'https://liuhonghe@github.com':  
Counting objects: 6, done.  
Delta compression using up to 4 threads.  
Compressing objects: 100% (5/5), done.  
Writing objects: 100% (6/6), 640 bytes | 0 bytes/s, done.  
Total 6 (delta 2), reused 0 (delta 0)  
To https://liuhonghe@github.com/liuhonghe/test.git  
   be08923..7c62aea  master -> master  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git tag -a v0 -m "tag for v0"  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git push  
Password for 'https://liuhonghe@github.com':  
Everything up-to-date  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git push --tag  
Password for 'https://liuhonghe@github.com':  
Counting objects: 1, done.  
Writing objects: 100% (1/1), 168 bytes | 0 bytes/s, done.  
Total 1 (delta 0), reused 0 (delta 0)  
To https://liuhonghe@github.com/liuhonghe/test.git  
 * [new tag]         v0 -> v0  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git pull  
From https://github.com/liuhonghe/test  
 * [new branch]      fetcher    -> origin/fetcher  
Already up-to-date.  
-> dreamoon@lhh-mac ~/git/test git:(master) 1☺ git pull origin fetcher  
From https://github.com/liuhonghe/test  
 * branch            fetcher    -> FETCH_HEAD  
Already up-to-date.  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ echo "add some test th" >> test.txt  
-> dreamoon@lhh-mac ~/git/test git:(master) ✗ ☺ git add .  
-> dreamoon@lhh-mac ~/git/test git:(master) ✗ ☺ git commit -m "add some test on master"  
[master ad07693] add some test on master  
 1 file changed, 1 insertion(+)  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git checkout v0  
Note: checking out 'v0'.  
  
You are in 'detached HEAD' state. You can look around, make experimental  
changes and commit them, and you can discard any commits you make in this  
state without impacting any branches by performing another checkout.  
  
If you want to create a new branch to retain commits you create, you may  
do so (now or later) by using -b with the checkout command again. Example:  
  
  git checkout -b <new-branch-name>  
  
HEAD is now at 7c62aea... Merge branch 'master' of https://github.com/liuhonghe/test  
-> dreamoon@lhh-mac ~/git/test git:(7c62aea) ☺ git push origin master  
Password for 'https://liuhonghe@github.com':  
Counting objects: 3, done.  
Delta compression using up to 4 threads.  
Compressing objects: 100% (3/3), done.  
Writing objects: 100% (3/3), 321 bytes | 0 bytes/s, done.  
Total 3 (delta 1), reused 0 (delta 0)  
To https://liuhonghe@github.com/liuhonghe/test.git  
   7c62aea..ad07693  master -> master  
-> dreamoon@lhh-mac ~/git/test git:(fetcher) ☺ git checkout master  
Switched to branch 'master'  
Your branch is up-to-date with 'origin/master'.  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git branch -d fetcher  
Deleted branch fetcher (was 7c62aea).  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git push --delete origin fetcher #删除远程分支  
Password for 'https://liuhonghe@github.com':  
To https://liuhonghe@github.com/liuhonghe/test.git  
 - [deleted]         fetcher  
-> dreamoon@lhh-mac ~/git/test git:(master) ☺ git push origin :fetcher #第二种删除远程分支  
» 转载请注明来源:若我若鱼 » git 远程操作(五)

Leave a Reply

Your email address will not be published. Required fields are marked *

five × three =