Git 常用操作(二)


第一次传数据:
echo "# miya" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/zhao520a1a/miya.git
git push -u origin master


分支操作:
查看分支:git branch
创建分支:git branch <name>
切换分支:git checkout <name>
创建+切换分支:git checkout -b <name>
合并某分支到当前分支:git merge <name>
删除分支:git branch -d <name>


看不到git远程分支??
先用fetch命令更新remote索引。
$ git fetch
再查看remote分支,发现已经可以看到目标分支branch170628_foo。
$ git branch -a

查看远程分支  git branch -r

使用下面两条命令来删除远程分支

git branch -r -d origin/branch-name 

git push origin :branch-name 

本地分支push到github上的远程分支上:

git push origin Sso_service:Sso_service    (本地分支名:远程分支名)

提示出错信息:fatal: remote origin already exists.
    解决办法如下:
    1、先输入$ git remote rm origin
    2、再输入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!
    3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容
    4、找到你的github的安装路径,我的是C:UsersASUSAppDataLocalGitHubPortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8etc
    5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

原文地址:https://www.cnblogs.com/zhaojinxin/p/8483567.html