【git】创建一个新的本地仓库并上传代码

参考 http://liuhui998.com/2011/02/28/git-adventures-local-repository/


root@Ubuntu32:/home/zhangbin/alex/gitProject# ls
gitweb-theme   meTestLocalBufferQueue.git

新建一个文件夹
root@Ubuntu32:/home/zhangbin/alex/gitProject# mkdir mePlayer.git


进入
root@Ubuntu32:/home/zhangbin/alex/gitProject# cd mePlayer.git/


空的

root@Ubuntu32:/home/zhangbin/alex/gitProject/mePlayer.git# ls


创建一个文件先
root@Ubuntu32:/home/zhangbin/alex/gitProject/mePlayer.git# echo "a player by me" >REDEME.MD


root@Ubuntu32:/home/zhangbin/alex/gitProject/mePlayer.git# ls
REDEME.MD


初始化git 
root@Ubuntu32:/home/zhangbin/alex/gitProject/mePlayer.git#git init  最好不要用这个,要用 git --bare init

nitialized empty Git repository in /home/zhangbin/alex/gitProject/meAlayer.git/.git/


加入这个新文件到git中

root@Ubuntu32:/home/zhangbin/alex/gitProject/meAHPlayer.git# git add .


然后commit:

root@Ubuntu32:/home/zhangbin/alex/gitProject/mePlayer.git# 
root@Ubuntu32:/home/zhangbin/alex/gitProject/mePlayer.git# git commit -m "project init 20140305"
[master (root-commit) 5551538] project init 20140305
 1 file changed, 1 insertion(+)
 create mode 100644 REDEME.MD


这样就有了。在gitweb中,也立即可以看到了。
root@Ubuntu32:/home/zhangbin/alex/gitProject/mePlayer.git# 



###################################

root@Ubuntu32:/home/zhangbin/alex/mePLAY# git push origin master
Counting objects: 7539, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7377/7377), done.
Writing objects: 100% (7538/7538), 101.14 MiB | 3.10 MiB/s, done.
Total 7538 (delta 2468), 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 file:///home/zhangbin/alex/gitProject/mePlayer.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'file:///home/zhangbin/alex/gitProject/mePlayer.git'


=============================================

参考 http://www.cnblogs.com/abeen/archive/2010/06/17/1759496.html

在使用Git Push代码到数据仓库时,提示如下错误:

[remote rejected] master -> master (branch is currently checked out)
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 [email protected]:/var/git.server/.../web
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '[email protected]:/var/git.server/.../web'

这是由于git默认拒绝了push操作,需要进行设置,修改.git/config添加如下代码:

    [receive]
    denyCurrentBranch = ignore

 

在初始化远程仓库时最好使用 git --bare init   而不要使用:git init

   如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时,   如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题), 那么push后的结果不会反应在work tree上,  也即在远程仓库的目录下对应的文件还是之前的内容,必须得使用git reset --hard才能看到push后的内容.


http://cpbest.blog.163.com/blog/static/4124151920125292010825/


根据上面所报的信息,它的意思就是默认情况下,git不允许用push操作更新non-bare的仓库,因为这样的操作会导致remote仓库的索引 (index)和工作树(work tree)与你push的不一致,此时需要通过‘git reset –hard’操作来使得工作树与HEAD索引相匹配。 可以通过在remote端,

##################################

另外,gitweb看不到更新的情况。


我发现我虽然加了remote的origin,但是push都到本地了。

并没有上传到远程。


于是,应该先pull到本地,然后再添加本地新的文件,commit之后push到远程。



root@Ubuntu32:/home/zhangbin/alex/# cd mePLAY/

在本地要上传的工程里头,也要先git init下,否则会报错。

root@Ubuntu32:/home/zhangbin/alex/mePLAY# git init


Initialized empty Git repository in /home/zhangbin/alex/mePLAY/.git/
root@Ubuntu32:/home/zhangbin/alex/mePLAY/.git# git add remote origin  file:///home/zhangbin/alex/gitProject/meAHPlayer.git

fatal: This operation must be run in a work tree


root@Ubuntu32:/home/zhangbin/alex//mePLAY/.git# cd ..

‘命令敲错了:
root@Ubuntu32:/home/zhangbin/alex//mePLAY#
git add remote origin file:///home/zhangbin/alex/gitProject/meAHPlayer.git
fatal: pathspec 'remote' did not match any files


root@Ubuntu32:/home/zhangbin/alex/mePLAY# gitremote add origin  file:///home/zhangbin/alex/gitProject/meAHPlayer.git



root@Ubuntu32:/home/zhangbin/alex/mePLAY# git add .


下载回来先
root@Ubuntu32:/home/zhangbin/alex//mePLAY#
git pull origin master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From file:///home/zhangbin/alex/gitProject/meAHPlayer
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 3, done.
Writing objects: 100% (3/3), done.
Total 3 (delta 0), reused 0 (delta 0)
warning: There are too many unreachable loose objects; run 'git prune' to remove them.


root@Ubuntu32:/home/zhangbin/alex/mePLAY# git push origin master
Counting objects: 7539, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7377/7377), done.
Writing objects: 100% (7538/7538), 101.14 MiB | 2.64 MiB/s, done.
Total 7538 (delta 2468), reused 0 (delta 0)
To file:///home/zhangbin/alex/gitProject/meAHPlayer.git
   5551538..b29b9f6  master -> master
root@Ubuntu32:/home/zhangbin/alex//handset_software/me



这样在gitweb就可以看到了。

猜你喜欢

转载自blog.csdn.net/commshare/article/details/20526369