300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > ubuntu 本地+远程(局域网)创建git仓库init+clone+add+commit+pull+push+remote

ubuntu 本地+远程(局域网)创建git仓库init+clone+add+commit+pull+push+remote

时间:2019-09-30 22:48:12

相关推荐

ubuntu 本地+远程(局域网)创建git仓库init+clone+add+commit+pull+push+remote

ubuntu14.04 本地+远程(局域网)创建git仓库init+clone+add+commit+pull+push+remote等命令(实际验证通过)

1、安装git :sudo apt-get install git

2、安装依赖:sudo apt-get install git-core python-setuptools openssh-server openssh-client

3、创建仓库文件管理目录:mkdir /home/wohao/gitRepository -p

4、复制源码到目录中:cp sourceCore/home/wohao/gitRepository -r /*sourceCore 为需要加到仓库的源文件*/

5、初始化仓库:使用:git --bare init sourceCore

说明:git init 和git –bare init 的具体区别?

6、下载到本地:git clone /home/wohao/gitRepository/sourceCore/.git/d

7、修改添加本地文件:

git status 查看工作区代码相对于暂存区的差别git add . 将当前目录下修改的所有代码从工作区添加到暂存区 . 代表当前目录git commit -m ‘注释’ 将缓存区内容添加到本地仓库git pull origin master先将远程仓库master中的信息同步到本地仓库master中git push origin master 将本地版本库推送到远程服务器,origin是远程主机,master表示是远程服务器上的master分支和本地分支重名的简写,分支名是可以修改的具体说明链接:/p/2e1d551b8261

8、问题解决:git push -f origin master

Counting objects: 35, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (24/24), done.

Writing objects: 100% (24/24), 36.92 KiB | 0 bytes/s, done.

Total 24 (delta 18), reused 0 (delta 0)

remote: error: refusing to update checked out branch: refs/heads/master

remote: error: By default, updating the current branch in a non-bare repository

remote: error: is denied, because it will make the index and work tree inconsistent

remote: error: with what you pushed, and will require 'git reset --hard' to match

remote: error: the work tree to HEAD.

remote: error:

remote: error: You can set 'receive.denyCurrentBranch' configuration variable to

remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into

remote: error: its current branch; however, this is not recommended unless you

remote: error: arranged to update its work tree to match what you pushed in some

remote: error: other way.

remote: error:

remote: error: To squelch this message and still keep the default behaviour, set

remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

To /home/wuhao/gitRepository/fs/.git/

! [remote rejected] master -> master (branch is currently checked out)

error: 无法推送一些引用到 '/home/wuhao/gitRepository/fs/.git/'

我当时遇到如下问题,尝试几种办法都解决不了,最后就是一个命令的问题:

再git的厂库路径执行

cd/home/wuhao/gitRepository/fs

git config --bool core.bare true

再次使用上面命令,本地和远程就能正常同步和合并了

wuhao@wuhao:~/1.0TB.1/workspace/kernel/branches/srcFs/fs/f2fs$ git add -A

wuhao@wuhao:~/1.0TB.1/workspace/kernel/branches/srcFs/fs/f2fs$ git commit -m 'extentcache*'

[master cdd2c85] extentcache*

4 files changed, 172 insertions(+)

create mode 100644 f2fs/extentcache.c

create mode 100644 f2fs/extentcache.h

create mode 100644 f2fs/extentcacheintterface.c

create mode 100644 f2fs/extentcacheintterface.h

wuhao@wuhao:~/1.0TB.1/workspace/kernel/branches/srcFs/fs/f2fs$

wuhao@wuhao:~/1.0TB.1/workspace/kernel/branches/srcFs/fs/f2fs$ git pull

Already up-to-date.

wuhao@wuhao:~/1.0TB.1/workspace/kernel/branches/srcFs/fs/f2fs$ git push origin master

Counting objects: 13, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (9/9), done.

Writing objects: 100% (9/9), 1.91 KiB | 0 bytes/s, done.

Total 9 (delta 5), reused 0 (delta 0)

To /home/wuhao/gitRepository/fs/.git/

38748db..cdd2c85 master -> master

wuhao@wuhao:~/1.0TB.1/workspace/kernel/branches/srcFs/fs/f2fs$

wuhao@wuhao:~/1.0TB.1/workspace/kernel/branches/srcFs/fs/f2fs$ git log

commit cdd2c850d02be1aea8c061b50db7a21ee2025ac3

Author: wohao <wo_wuhao@>

Date: Tue Nov 17 13:48:56 +0800

extentcache*

9、局域网共享仓库

1)、查看本地ip地址:ifconfig

eth0 Link encap:以太网 硬件地址 60:45:cb:6c:f3:c4

inet 地址:192.168.16.89 广播:192.168.16.255 掩码:255.255.255.0

inet6 地址: fe80::6245:cbff:fe6c:f3c4/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1

接收数据包:64434 错误:0 丢弃:0 过载:0 帧数:0

发送数据包:36844 错误:0 丢弃:0 过载:0 载波:0

碰撞:0 发送队列长度:1000

接收字节:44321161 (44.3 MB) 发送字节:14576427 (14.5 MB)

2)、克隆仓库文件:git clone git@192.168.16.89:/home/wuhao/gitRepository/fs/.git

报错:

wuhao@wuhao:~/workspace/gitTest$ git clone git@192.168.16.89:/home/wuhao/gitRepository/fs/.git

正克隆到 'fs'...

The authenticity of host '192.168.16.89 (192.168.16.89)' can't be established.

ECDSA key fingerprint is a9:67:bf:c3:2c:ba:a4:0d:2f:e6:a7:89:63:9d:a0:1f.

Are you sure you want to continue connecting (yes/no)? yew

Please type 'yes' or 'no': yes

Warning: Permanently added '192.168.16.89' (ECDSA) to the list of known hosts.

git@192.168.16.89's password:

Permission denied (publickey,password).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

wuhao@wuhao:~/workspace/gitTest$

解决:需要安装ssh相关的服务端和client客户端

sudo apt-get install openssh-server

sudo apt-get install openssh-client

sudo /etc/init.d/ssh start

wuhao@wuhao:~/workspace/gitTest$ ps -e |grep sshd

1116 ? 00:00:00 sshd

wuhao@wuhao:~/workspace/gitTest$

3)、从新克隆测试,或者在另一台机器上测试

wuhao@wuhao:~/workspace/gitTest$ git clone git@192.168.16.89:/home/wuhao/gitRepository/fs/.git

正克隆到 'fs'...

git@192.168.16.89's password:

remote: Counting objects: 2451, done.

remote: Compressing objects: 100% (2448/2448), done.

remote: Total 2451 (delta 580), reused 0 (delta 0)

接收对象中: 100% (2451/2451), 8.56 MiB | 9.05 MiB/s, done.

处理 delta 中: 100% (580/580), done.

检查连接... 完成。

wuhao@wuhao:~/workspace/gitTest$

10、补充:设置git信息

git config --global user.email "you@"

git config --global user.name "Your Name"

11、跟换远程仓库ULR

git remote -v # 查看当前远程仓库地址

git remote set-url origin <new url> # 修改远程地址为新的地址 <new url> 改为新的地址

修改:

wuhao@wuhao:~/1.0TB.1/workspace/gitTest/fs$ ifconfig

eth0 Link encap:以太网 硬件地址 60:45:cb:6c:f3:c4

inet 地址:192.168.16.9 广播:192.168.16.255 掩码:255.255.255.0

inet6 地址: fe80::6245:cbff:fe6c:f3c4/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1

接收数据包:42092 错误:0 丢弃:0 过载:0 帧数:0

发送数据包:20519 错误:0 丢弃:0 过载:0 载波:0

碰撞:0 发送队列长度:1000

接收字节:25594243 (25.5 MB) 发送字节:3194346 (3.1 MB)

git remote set-url origin git@192.168.16.9:/home/wuhao/gitRepository/fs/.git

git remote -v

origin git@192.168.16.9:/home/wuhao/gitRepository/fs/.git (fetch)

origin git@192.168.16.9:/home/wuhao/gitRepository/fs/.git (push)

git remote show origin # 再次查看当前仓库远程地址 确认是否发生改变

git@192.168.16.9's password:

* 远程 origin

获取地址:git@192.168.16.9:/home/wuhao/gitRepository/fs/.git

推送地址:git@192.168.16.9:/home/wuhao/gitRepository/fs/.git

HEAD 分支:master

远程分支:

master 已跟踪

为 'git pull' 配置的本地分支:

master 与远程 master 合并

为 'git push' 配置的本地引用:

master 推送至 master (最新)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。