服务器
安装Git
添加git用户
adduser git -m
设置密码
passwd git
切换到git用户,新建repos目录,在该目录下新建库hello.git目录,
cd到hello.git目录,初始化该库:
git --bare init hello.git
这样就新建了一个hello的远程库,这个库是空的。
本地
安装git
配置用户名和邮箱
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS"
假设本地已有一个和远程库同名的hello项目,进入到该项目下,初始化该库
git init
将所有文件添加到本地库索引
git add -A
提交工作目录树中的所有文件到本地库
git commit -a -m "init commit"
这时通过以下命令可查看本地分支:
git branch -a
列出的分支中,带有*的为本地分支,其他为远程分支。
要查看远程分支信息,执行命令:
git remote -v
如果输出信息为空,表示还没有添加远程主机,通过以下命令添加:
git remote add <主机名> <网址>
例如:
git remote add origin git@192.168.1.110:repos/hello.git
最后,将本地库push到上面的远程库:
git push origin master
origin 是远程库主机名, master是本地分支名,如果该远程分支不存在,则会被新建。
输入git用户的密码完成push。
如果远程仓库不为空的话,需要先执行pull,取回远程主机某个分支的更新,再与本地的指定分支合并.
git pull origin master
如果操作过程提示错误:
fatal: Unable to create temporary file: Permission denied
表示服务器git库目录权限问题,修改成git用户及git用户组就可以了。
参考:
http://www.ruanyifeng.com/blog/2014/06/git_remote.html
1、创建本地分支 local_branch
git branch local_branch
2、创建本地分支local_branch 并切换到local_branch分支
git checkout -b local_branch
3、切换到分支local_branch
git checkout local_branch
4、推送本地分支local_branch到远程分支 remote_branch并建立关联关系
a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch
git push
b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch
git push -u origin/remote_branch
c.远程没有有remote_branch分支并,本地已经切换到local_branch
git push origin local_branch:remote_branch
5、删除本地分支local_branch
git branch -d local_branch
6、删除远程分支remote_branch
git push origin :remote_branch
git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。
git branch -d | -D branchname 删除branchname分支
git branch -d -r branchname 删除远程branchname分支
7、查看本地分支
git branch
8、查看远程和本地分支
git branch -a