1

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?

4
  • Well as the error says, you need a remote to be able to push.
    – adarsh
    Commented Feb 18, 2016 at 0:43
  • Yes, indeed. However, neither the post on Hacker News, nor any of the derived blog posts need that step, so that seems strange at first sight. As I have stated in another comment: What is the correct remote url for a local, bare Git repository on a Windows system?
    – so23
    Commented Feb 18, 2016 at 0:54
  • None. If it is a local repo then you don't need to push it anywhere.
    – Massey101
    Commented Feb 18, 2016 at 0:57
  • As I have written in a comment below, the correct url is the file system path.
    – so23
    Commented Feb 18, 2016 at 1:02

3 Answers 3

1

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
5
  • What is the correct remote url for a local, bare Git repository on a Windows system?
    – so23
    Commented Feb 18, 2016 at 0:50
  • @so23 Try to use the hostname of your windows server Commented Feb 18, 2016 at 0:52
  • Indeed, thank you very much. In the context of the Hacker News post, one has to do a config remote add origin "/c/Users/username/Desktop/.myconf/", followed by a config push --set-upstream origin master.
    – so23
    Commented Feb 18, 2016 at 1:01
  • I don't think that is correct. .myconf is performing the same role as a .git would normally. If you push to it you will be pushing the repo back to itself. If you just want a local repo then you are done, no need to push.
    – Massey101
    Commented Feb 18, 2016 at 1:12
  • Okay I can confirm that this is indeed what would happen and that git will not allow you to do this. If you have a remote repository you can set it up my answer. Otherwise there is not need to push anywhere. I think the link just used git push as an example.
    – Massey101
    Commented Feb 18, 2016 at 1:26
0

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/

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.