1. 分支管理操作
[root@localhost ~]# mkdir branch
[root@localhost ~]# cd branch/
[root@localhost branch]# git init
Initialized empty Git repository in /root/branch/.git/
[root@localhost branch]# echo "first branch demo" > branch.txt
[root@localhost branch]# git add branch.txt
[root@localhost branch]# git commit -m "first branch commit"
[master (root-commit) 1e67ee5] first branch commit
1 file changed, 1 insertion(+)
create mode 100644 branch.txt
[root@localhost branch]# git branch feature_x
[root@localhost branch]# git branch
feature_x
* master # *说明当前在哪个分支上
[root@localhost branch]# git checkout feature_x #切换分支
Switched to branch 'feature_x'
[root@localhost branch]# git branch
* feature_x
master
[root@localhost branch]# echo "new feature added" >> branch.txt
[root@localhost branch]# git add branch.txt
[root@localhost branch]# git commit -m "new feature"
[feature_x fb6272c] new feature
1 file changed, 1 insertion(+)
[root@localhost branch]# git status
On branch feature_x
nothing to commit, working directory clean
[root@localhost branch]# git checkout master #要合并分支必须先切换到主分支
Switched to branch 'master'
[root@localhost branch]# git merge feature_x
Updating 1e67ee5..fb6272c
Fast-forward
branch.txt | 1 +
1 file changed, 1 insertion(+)
[root@localhost branch]# cat branch.txt
first branch demo
new feature added
如果觉得这个分支没有用 可以删除掉
[root@localhost branch]# git branch -d feature_x
Deleted branch feature_x (was fb6272c).
[root@localhost branch]# git branch
* master
2. git pull 命令说明(忽略)
git pull命令的作用是:取回远程主机某个分支的更新,再与本地的指定分支合并。
基本用法:
git pull
git push 不行的时候 git pull一下 再push