一些常用的Git命令

一、在本地创建一个仓库

mkdir mystudygit
cd mystudygit
git init        //创建仓库
ls -a          //查看是否创建仓库成功

二、在仓库下添加文件

git add cxf.txt
git commit -m "add cxf.txt commit"

三、为本地项目添加远程仓库

//为项目添加远程仓库 studygit 是远程仓库地址的别名,这个可以随便写,默认是origin
//可以添加多个远程仓库
git remote add studygit https://github.com/仓库

查看添加的远程仓库

git remote -v

//将本地的代码“推”到远程服务器上(将本地master分支推到远程master分支上)

git push studygit master

四、从github中download仓库

//克隆远程仓库到本地仓库名称是msgmail
git clone https://github.com/仓库名  msgmail

拓展

//从远程仓库抓取数据
git fetch [remote-name]

//推送数据到远程仓库
git push origin master

//远程仓库的删除
git remote rm name

//强推,即利用强覆盖的方式将本地的代码替换远程git仓库的内容
git push -f origin

//提交本地test分支作为远程的master分支 
git push origin test:master

//将本地的master分支提交到远程的master分支上
git push origin master

//将当前所在的branch 推到origin对应的branch中,例如:当前在master分支中,则会将本地的修改推到远程的master分支上
git push origin
 

//远程仓库的重命名

git remote rename old_name new_name	

五、git 修改本地和远程分支名称

git branch -a #查看所有分支 
git branch -r #查看远程分支 
git branch -vv #查看本地分支所关联的远程分支

git branch -m old_branch new_branch # Rename branch locally 
git push origin :old_branch # Delete the old branch 
git push --set-upstream origin new_branch 或者git push -u origin new_branch# Push the new branch, set local branch to track the new remote

注意:把origin改为自己的名称

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值