git 使用

 

1、clone git项目使用的协议 一般是 https 或者ssh,如果是https则每次push到远程服务器时要输入用户名用户密码

  如果你选了 git 协议,则不能push,会报错,参看: [Github] fatal: remote error: You can't push to git 解决办法

 

 

2、.gitignore 文件常用配置

# for eclipse
.settings/
.project
.classpath

# for idea
*.iml
/.idea
*/target
.DS_Store
.gitattributes

 

 

3、密钥生成,然后保存,并把公钥加入到 github 或 oschina等平台上。

 

 4、用户名,用户邮箱设置, 分针对 整个操作系统,针对用户,针对项目 三个级别。

命令分别是:

1) git config 针对一个git仓库
2) git config --global    针对一个用户
3) sudo git config --system    针对一个系统,因为是针对整个系统的,所以必须使用sudo

 

 

  一般自己在开源平台上用的email address跟公司项目不一样,这时可以把 公司的设成用户默认的,而自己的项目单独设置。

 

针对项目设置用户名 和邮箱,添加 user.name 和 user.email两个属性,其实就是修改 .git目录下的config文件。

[user]
 email=your email
 name=your name

 

 

 5、 无法push到远程服务器的问题,重新关联远程库

$ git remote -v
$ git remote rm origin  
$ git remote add origin git@github.com:user_name/user_repo.git  
$ git push origin  

 

参考: 

  1、http://stackoverflow.com/questions/32238616/git-push-fatal-origin-does-not-appear-to-be-a-git-repository-fatal-could-n 

  2、 [Github] fatal: remote error: You can't push to git 解决办法

First, check that your origin is set by running

git remote -v

This should show you all of the push / fetch remotes for the project.

If this returns with no output, skip to last code block.

Verify remote name / address

If this returns showing that you have remotes set, check that the name of the remote matches the remote you are using in your commands.

$git remote -v
myOrigin ssh://git@example.com:1234/myRepo.git (fetch)
myOrigin ssh://git@example.com:1234/myRepo.git (push)

# this will fail because `origin` is not set
$git push origin master

# you need to use
$git push myOrigin master

If you want to rename the remote or change the remote's URL, you'll want to first remove the old remote, and then add the correct one.

Remove the old remote

$git remote remove myOrigin

Add missing remote

You can then add in the proper remote using

$git remote add origin ssh://git@example.com:1234/myRepo.git

# this will now work as expected
$git push origin master

 

 

6、添加多个远程库,从多个github 库同步代码

  先fork一个库,然后clone到本地,然后添加另外一个远程库,fetch,然后切换到master,将新添加的远程库的master版本合并到master,最后push即可

  参考: git使用之五——Github上fork项目后与原项目保持同步

 

7、

 

posted @ 2017-04-01 17:11  xunux  阅读(278)  评论(0编辑  收藏  举报