简体   繁体   中英

Push to bare git repository without cloning it beforehand

I am currently trying to save some files in a bare git repository, as described here:

https://news.ycombinator.com/item?id=11071754

However, I am trying this with Git for Windows, and not on a Linux machine. The bare git repository gets created, but I am struggling to get the push working correctly. This is what I have done:

username@hostname MINGW64 ~/Desktop
$ mkdir .myconf

username@hostname MINGW64 ~/Desktop
$ git init --bare "/c/Users/username/Desktop/.myconf"
Initialized empty Git repository in C:/Users/username/Desktop/.myconf/

username@hostname MINGW64 ~/Desktop
$ alias config="git --git-dir='/c/Users/username/Desktop/.myconf' --work-tree='/c/Users/username/Desktop/'"

username@hostname MINGW64 ~/Desktop
$ config config status.showUntrackedFiles no

username@hostname MINGW64 ~/Desktop
$ config status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

username@hostname MINGW64 ~/Desktop
$ config add test.txt

username@hostname MINGW64 ~/Desktop
$ config commit -m "Added test file."
[master (root-commit) a587ec1] Added test file.
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

Everything so far has worked correctly. However, when I try to push , this happens:

username@hostname MINGW64 ~/Desktop
$ config push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

Also a push to origin master does not work:

username@hostname MINGW64 ~/Desktop
$ config push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Apparently, git wants a push destination.

I have not seen that setting such a destination is a necessary step in the linked description (nor in any derived blog posts), and I am unsure how to do that with Git for Windows. How can this be solved?

You need to define a remote so Git knows where to push to. The default remote is called origin and will be the url for Git to push to.

For example, if you were trying to push to the Linux Kernel the command would be:

git remote add origin https://github.com/torvalds/linux.git

You need to tell git where the remote repository is. Use:

config remote add origin "<path>"

Where path is either a url or directory.

If you wish to understand why .myconfig is not a remote repo that you push to read through something like this: http://www.sbf5.com/~cduan/technical/git/

For distributed VCS such as git, the push is a synchronization mechanism between local branch and remote branch. you must specify the connection of local branch and remote branch before you do push, for which in git, it reference as "upstream" or "tracking".

If you want to push your commit to remote without clone. you can add the remote repository as a new remote, checkout the branch you want to commit to and make it track the remote branch, add your modification to this new branch and do push.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM