0

I got little bit lazy, so I wanted to take a shortcut:

I wanted to upload some new programming examples to my GIT remote repo, so I created VS solution (for non .NET pepole, just a simple directory) on my desktop. So it looks like this:

  • Desktop
    • some desktop file.txt
    • some catalog
    • MyProgrammingExamples

So, in order to push MyProgrammingExamples onto GitHub repo, I navigated in PowerShell to my desktop, fired

git init
git add MyProgrammingExamples
git commit -m 'some message'

Now, I'd liek it to push it onto remote, so further I run commands:

git remote add 'url to my repo'
git push origin master

But it gives me:

fatal: The current branch master has no upstream branch.

So I tried:

git remote add master --mirror=push 'url to my repo'

which reulsted in

fatal: remote master already exists.

Well, it would be good that someone explain what is hapenning, but what I am really after is to how to achieve my goal, i.e. create catalog somewhere (anywhere, not a GIT catalog) and then easily push it to existing remote repository.

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
  • Git does not have an entity that it calls a "catalog" so I have no idea what you mean by "catalog" here, but you almost certainly don't want a push mirror. In general if you are dealing with some existing Git repository on some other machine, you should start by *cloning* it, not by creating a new Git repository on your own machine. – torek Mar 27 '20 at 16:02
  • @torek I didn't mean "git entity", but something that maps to catalog on local repo. I just want to push new catalog to github remote repo. I have a workaround, stated below in my answer. – Michał Turczyn Mar 27 '20 at 16:06
  • I don't know what you mean by "catalog on local repo" either. Again, that's not a Git term. Your question title begins with "create new Git catalog" and ends with "clean Git catalog"; perhaps you should rephrase it? (This is probably some kind of English/other-language translation glitch.) (Polish? Anyway, as a guess, maybe by "catalog" you mean what most people call either a "directory" or a "folder"? That is, an entity that the OS requires that you create in order to hold file's names.) – torek Mar 27 '20 at 16:11
  • @torek Thanks for remarks, I used terms catalog/directory/folder interchangeably. – Michał Turczyn Mar 27 '20 at 16:35

2 Answers2

0

According to this SO post, such operation is impossible, but there's workaround:

# create new branch and commit to it, then push to origin
# (assumed, that remote repo is already added, as in question)
git checkout -b single_file_branch
git add file_to_add_to_repo
git commit -m 'some message'
git push origin

Then we switch to local repo connected to the remote one, which is up to date and do:

# pull newest changes (as well as the branch)
git pull
# merge branches, allowing unrelated histories (without it it would generate an error)
git merge --allow-unrelated-histories origin/single_file_branch
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
0

You can create a new repo right from visual studio, just signin to github from visual studio and then use the git menu in visual studio to do all the stuff supported by git!

Usman Amin
  • 11
  • 1
  • 4