- 添加新文件
- 创建新分支
[root@localhost ~]# cd /tmp/test/
[root@localhost test]# ls
1.txt README.md
[root@localhost test]# git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:hellopasswd/test
d3231be..798b8a1 master -> origin/master
Updating d3231be..798b8a1
Fast-forward
2.doc | 1 +
1 file changed, 1 insertion(+)
create mode 100644 2.doc
[root@localhost test]# ls
1.txt 2.doc README.md
[root@localhost test]# git branch
* master
查看所有分支
[root@localhost test]# git ls-remote origin
798b8a137d65fd7ed86d116246881582bd509f7d HEAD
798b8a137d65fd7ed86d116246881582bd509f7d refs/heads/dev
798b8a137d65fd7ed86d116246881582bd509f7d refs/heads/master
远程分支
[root@localhost test]# git checkout -b dev origin/dev
fatal: Cannot update paths and switch to branch 'dev' at the same time.
Did you intend to checkout 'origin/dev' which can not be resolved as commit?
[root@localhost test]# git fetch
From github.com:hellopasswd/test
* [new branch] dev -> origin/dev
[root@localhost test]# git checkout -b dev origin/dev
Branch dev set up to track remote branch dev from origin. #分支dev设置为跟踪来自origin的远程分支dev
Switched to a new branch 'dev' #切换到一个新分支
[root@localhost test]# git branch
* dev
master
[root@localhost test]# echo "333" >> 3.txt
[root@localhost test]# git add 3.txt
[root@localhost test]# git commit -m "add 3.txt"
[dev 9dc62e6] add 3.txt
Committer: root <root@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
create mode 100644 3.txt
[root@localhost test]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 326 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:hellopasswd/test.git
798b8a1..9dc62e6 dev -> dev
查看dev和master文件的不同
当dev和master文件都有更新时,在push时,两个分支都会同时更新,若本地分支比远程的分支多,
指定分支
[root@localhost test]# git push origin dev
Everything up-to-date
本地分支比远程分支多
[root@localhost test]# git branch dev2
[root@localhost test]# git branch
* dev
dev2
master
[root@localhost test]# git checkout dev2
Switched to branch 'dev2'
[root@localhost test]# echo "dev2" >> dev2.txt
[root@localhost test]# git add dev2.txt
[root@localhost test]# git commit -m "add dev2.txt"
[dev2 f5a6198] add dev2.txt
Committer: root <root@localhost.localdomain>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
create mode 100644 dev2.txt
[root@localhost test]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Everything up-to-date
[root@localhost test]# git push origin dev2
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 270 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To git@github.com:hellopasswd/test.git
* [new branch] dev2 -> dev2
查看是否存在dev2