1

I just want to upload some files to my already existing github.com account.

I'm perplexed by that push-pull github instructions and would be very grateful if someone just instructed me (in a pedestrian way) how to put a new file in an already existing directory at my github account.

I'm a Debian user and with the other servers I just make use of sftp user@server.com and then cd directory and then put file

What is a direct translation of this procedure for a github server?

What I need is that myRepo = XYZ contains no files (apart from, say, README) but only a number of directories dir1, dir2, dir3, ,,, each containing files and subdirectories dir11, dir12, ,,, dir21, ... and I simply cannot find out how to to do that.

On my Supercomputer account I made a git directory and on Github XYZ repository ("user-me" is for my real user name)

git clone https://github.com/user-me/XYZ
Cloning into 'XYZ'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.

On the supercomputer:

cd XYZ
mkdir dir1
git add dir1 

But then:

git commit
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
git push
Username for 'https://github.com': user-me
Password for 'https://user-me@github.com': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Mladen-Pavicic/MMPH/'

With the token it goes through:

git push
Username for 'https://github.com': user-me
Password for 'https://user-me@github.com': 
Everything up-to-date

But there is no change in https://github.com/user-me/XYZ

I also tried git commit dir1. The same.

What am I doing wrong?

Mladen
  • 31
  • 2
  • 1
    GitHub is a code hosting facility for source files; Git is the program used for revision control (similar to Svn, Mercurial, or CVS in the old days). It's not a server similar to what you'd access over FTP. Pushing and pulling are for updating a remote (server, in this case) with your changed code, and getting the latest changes from that remote that you or someone else pushed. I'm not sure how you ended up in a situation where you're treating GitHub as if it's a remote server, but they're really totally different things for different purposes. – Zac Anger Jan 02 '23 at 00:52
  • Welcome to SO! https://stackoverflow.com/questions/12258399/how-do-i-create-a-folder-in-a-github-repository - do you want to use git to create the new folder and add new files or do you want to use the GitHub UI (https://docs.github.com/en/repositories/working-with-files/managing-files/adding-a-file-to-a-repository)? – Christian Jan 02 '23 at 01:09

1 Answers1

1

If you want the content of a folder to be pushed to a new GitHub repository, the simplest option is to use the GitHub CLI command gh repo create.

  • First, install gh.

  • Second, authenticate yourself with gh auth login

  • Third:

    gh repo create my-project --source=. --push
    

It will do all the work for you:

  • initialize a new local Git repo
  • create a new GitHub repository under your account (change 'my-project' by a better name)
  • add, commit, and push to GitHub your local files under the current folder.

a colleague of mine formed some directories and added some files to my account.

That means you must first git clone the repository from your account:

cd /path/to/empty/folder
git clone github.com/yourAccount/yourRepo

Now I obtained new files through calculations on a supercomputer which I should put to Git to be available to scientists as referred in my recent published paper.

Assuming you have copied those files in /path/to/parent/newData, you can go to your local clone and add them:

cd /path/to/empty/folder/yourRepo
git --work-tree=/path/to/parent add newData
git commit -m "add new data"
git push
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Sounds like what you want to do is very basic pushing. Please read this: https://git-scm.com/docs/git-push. – Max Jan 02 '23 at 12:29
  • @Mladen A token is for HTTPS URLS, used in place of a password. An SSH URL only requires private/public key pair (with the possible addition of a passphrase, if you create your private key encrypted). – VonC Jan 02 '23 at 23:19
  • @Mladen Clone it, add you files and folders, git add, git commit and git push. – VonC Jan 05 '23 at 06:43
  • @VonC No-go. I edited my original post above. – Mladen Jan 05 '23 at 12:44
  • @Mladen you need to add a `.keep` file into `dir1`, then add, commit and push: Git does not version empty folders, only files. See "[How do I add an empty directory to a Git repository?](https://stackoverflow.com/q/115983/6309)" – VonC Jan 05 '23 at 13:43