初次接触git感觉svn真香(对于我这菜鸡简单有效就挺好)

最后没成功仅供本人记录经历,有时间再接着弄

首先创建好想要存放文件的目录并常见git仓储

1
mkdir /home/gituser/blogtest/myfiles.git

进入该文件初始化git仓储

1
2
cd /home/gituser/blogtest
git init

在本地需要上传的项目目录中鼠标右键打开Git Bash Here
查看当前项目提交代码的仓储地址

1
git remote -v 

如果已经存在origin先删除在add

1
2
git remote rm origin
git remote add origin user@xxxx.xxx:/home/gituser/blogtest/myfiles.git

执行完成后 git remote -v 可以看到链接变化
之后把需要提交的文件添加到git缓存中

1
git add <fileName>

之后可以查看add上的文件

1
git ls-files

之后提交到本地仓储中

1
git commit

传输到服务器仓储

1
git push origin master

发现报错了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Writing objects: 100% (15076/15076), 20.45 MiB | 5.40 MiB/s, done.
Total 15076 (delta 4403), reused 15074 (delta 4402), pack-reused 0
remote: Resolving deltas: 100% (4403/4403), done.
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: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To xxx.xxx:/home/gituser/blogtest
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'xxx.xxx:/home/gituser/blogtest'

查了下需要在服务器上修改git config代码如下

1
git config receive.denyCurrentBranch ignore

重新push成功


第一次push上去发现主题部分没有push成功并且add不上。因此我删了重新操作了一次这次主题部分也成功推到服务器。那就继续搞!!!


在本地新建个文件testblog测试上边推送的代码是否完整有效。
首先在文件夹中点击鼠标右键打开Git bash here初始化git仓库

1
git init

配置clone到服务器项目地址

1
git remote add origin user@xxxx.xxx:/home/gituser/blogtest/myfiles.git

将代码下载到本地

1
2
git pull
git pull origin master

下载成功,因为我上传的是blog项目,下载之后本地可以build运行,成功撒花~~