一.git的安装后的配置
1.添加配置信息
git config --global user.name "xxx"
git config --global user.email xxxxxxxxxxxxxxxxx //--global参数表示全局配置,对本机每个git项目均起作用
2.查询配置信息
gedit ~/.gitconfig
1.在需要的指定目录添加库:
git init //初始化一个空的库
2.向仓库中添加目录
git add +目录名 //所添加的目录只能是在仓库所在目录的子目录或根目录中,否则会提示fatal:'目录' is outside repository
3.提交
git commit -m 'message'
git commit -a --allow-empty-message
4.管理远程仓库(转载自http://selboo.com/post/928/)
查看当前的远程库
要查看当前配置有哪些远程仓库,可以用 git remote 命令,它会列出每个远程库的简短名字。在克隆完某个项目后,至少可以看到一个名为 origin 的远程库,Git 默认使用这个名字来标识你所克隆的原始仓库:
$ git clone git://github.com/schacon/ticgit.git
Initialized empty Git repository in /private/tmp/ticgit/.git/
remote: Counting objects: 595, done.
remote: Compressing objects: 100% (269/269), done.
remote: Total 595 (delta 255), reused 589 (delta 253)
Receiving objects: 100% (595/595), 73.31 KiB | 1 KiB/s, done.
Resolving deltas: 100% (255/255), done.
$ cd ticgit
$ git remote
origin
$ git remote -v
origin git://github.com/schacon/ticgit.git
$ cd grit
$ git remote -v
bakkdoor git://github.com/bakkdoor/grit.git
cho45 git://github.com/cho45/grit.git
defunkt git://github.com/defunkt/grit.git
koke git://github.com/koke/grit.git
origin [email protected]:mojombo/grit.git
$ git remote
origin
$ git remote add pb git://github.com/paulboone/ticgit.git
$ git remote -v
origin git://github.com/schacon/ticgit.git
pb git://github.com/paulboone/ticgit.git
$ git fetch pb
remote: Counting objects: 58, done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 44 (delta 24), reused 1 (delta 0)
Unpacking objects: 100% (44/44), done.
From git://github.com/paulboone/ticgit
* [new branch] master -> pb/master
* [new branch] ticgit -> pb/ticgit
$ git fetch [remote-name]
$ cd /opt/git
$ mkdir project.git
$ cd project.git
$ git --bare init
$ git push origin master
$ git remote show origin
* remote origin
URL: git://github.com/schacon/ticgit.git
Remote branch merged with 'git pull' while on branch master
master
Tracked remote branches
master
ticgit
$ git remote show origin
* remote origin
URL: [email protected]:defunkt/github.git
Remote branch merged with 'git pull' while on branch issues
issues
Remote branch merged with 'git pull' while on branch master
master
New remote branches (next fetch will store in remotes/origin)
caching
Stale tracking branches (use 'git remote prune')
libwalker
walker2
Tracked remote branches
acl
apiv2
dashboard2
issues
master
postgres
Local branch pushed with 'git push'
master:master
$ git remote rename pb paul
$ git remote
origin
paul
$ git remote rm paul
$ git remote
origin
git rm --cache -r +目录名 //--cache保证只会删除远程仓库里的目录,而不会影响本机的物理目录,-r是指递归删除
这个问题貌似是只出现在在一台机器上第一次登录某一帐号时才会出现,需要添加ssh key,具体做法是:
先尝试这个命令:
ssh -T [email protected]
如若未出现“.........success.....”字眼,则说明没有ssh key,进入~/.ssh目录下,键入:
ssh -keygen
一路回车,最后把id_rsa.pub.file 复制粘贴到github帐号的new ssh就Ok了!6. did you run git update-server-info on the server? 错误 或者 error: The requested URL returned error: 403 while accessing
修改~/.gitconfig
添加
[remote "origin"]
url = https://github.com/sucoder/origin.git