Search code examples
gitmacosgithubgithub-for-mac

Upload project folder to specific location (subfolder) in private git repo


I'm trying to upload a project folder to a specific location on a private repo using the terminal, but the process I'm following doesn't seem to work. Particularly, the folder where I want to upload the file has the following path:

https://github.com/username/repo_name/tree/master/folder_where_I_want_to_upload_another_folder

I tried to do the following in the local folder:

git init
git add .
git commit -m "my commit"
git remote add origin <remote repository folder URL>
git push origin master

Any idea on how to solve this?


Solution

  • The way that I would handle this is by first cloning the repo with

    git clone https://github.com/username/repo_name.git

    Then from here, If the folder_where_I_want_to_upload_another_folder doesn't exist, you would need to create it. Add your files/folders that you want uploaded here.

    If you just want to upload an empty folder though, you can't. From the git FAQs :

    Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it.

    Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own.

    You can say "git add " and it will add the files in there.

    If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose (there is also a tool MarkEmptyDirs using the .NET framework which allows you to automate this task); you can leave it empty or fill in the names of files you do not expect to show up in the directory.

    So now knowing this, add an empty .gitignore or, what I like even better, is to add a readme explaining the purpose of having an empty folder.

    Then from the root of the repo, run

    git add folder_where_I_want_to_upload_another_folder
    git commit -m "Added files and folders"
    git push origin master