在提交代码时,git如何忽略指定文件
当用git向github上传本地代码时,有时需要忽略一些本地某些文件如:node_modules或webStorm自动生成的.idea文件,只需要修改当前项目的根目录中的.gitignore,将要忽略的文件加入到此文本中。如下所示:
.idea/
node_modules/
logs/
.svn
*.iml
npm-debug.log
删除远程分支
git push origin :分支名
例如:要删除远程服务器上面的bugfix分支就可以用
git push origin :bugfix
删除本地分支
git branch -d 分支名
例如:要删除本地的bugfix分支,要首先跳转到非bugfix分支上面,然后运用
git branch -d bugfix
怎样修改默认上传分支
当运用git push
上传代码时出现如下错误时:
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:upgrade-201708
To push to the branch of the same name on the remote, use
git push origin v2.0-bugfix
To choose either option permanently, see push.default in 'git help config'.
可以通过设置默认值进行修正:git config --global push.default matching
nothing
: 意思是当git push
不上传任何东西。matching
: 上传所有可以匹配的分支代码,即本地分支和远程分支相同时所有的代码。upstream
: 上传当前分支代码到它的上游分支上面。current
: 上传当前分支代码到远程同名分支上面。simple
: 和upstream
具有相同的功能,但当上游分支名和当前分支名不一样时就会报错
查看本地配置
git config --global push.default