How to upload folders on GitHub

Github

Github Problem Overview


How can I upload folders to GitHub? I have all of my code in a folder, containing 98 files, on my desktop. I know how to upload files, but it there a way to upload the entire folder?

Thanks!

Github Solutions


Solution 1 - Github

This is Web GUI of a GitHub repository:

enter image description here

Drag and drop your folder to the above area. When you upload too much folder/files, GitHub will notice you:

> Yowza, that’s a lot of files. Try again with fewer than 100 files.

enter image description here

and add commit message

enter image description here

And press button Commit changes is the last step.

Solution 2 - Github

You can also use the command line, Change directory where your folder is located then type the following :

git init
git add <folder1> <folder2> <etc.>
git commit -m "Your message about the commit"
git remote add origin https://github.com/yourUsername/yourRepository.git
git push -u origin master
git push origin master  

Solution 3 - Github

I Understand where you are coming from.

The solution provided by @James Graham may not work in certain cases. The Drag and Drop Functionality may cease to exist. See below link when that happens: https://www.reddit.com/r/github/comments/meuxtg/github_drag_and_drop_not_working/

If somebody wants to avoid the shell and all the commands and wants to have a UI to do that,Github Desktop is one of the way to go forward.

Steps to follow to install and use Github Desktop:

I am assuming you know the difference between local repo and remote repo

  1. Install Github Desktop
  2. Create a repository locally on your hard drive by using github desktop. This will automatically create files like .git and .gitattributes. It also asks to create a README.md file, always best practice is to create it and edit it informing readers about your project overview, installation steps etc. README.md is rendered in Markdown and can also render HTML. See more about Markdown here: Markdown Cheatsheet guide
  3. Copy and Paste all the folders and files that you want to upload(basically the right terminology is "Push" ) into this newly created local repository. Be aware of the directory structure as the exact same directory structure will be replicated on your remote repository.
  4. Go to github desktop, as soon as you paste files in the local repo, you will see them as changes here. All you need to do is commit these changes with a comment. This will be your "First or Initial Commit" to the repo.
  5. Next Github repo will ask whether you want to publish these to its remote repository. Click "Publish" Note Publish is just a one time operations. Going forward any further changes you make to local repo will be seen in github desktop and you need to again follow the loop of "Commit local->Fetch from remote->Push to Remote. As long as you are the only developer working on a project you need not go into other mechanics of git branches etc.
  6. To verify if your repo is published remotely login to your github profile on the web and see your repository sitting there. This your remote repo which you effectively created from your local repo by using Github desktop.

Solution 4 - Github

I've just gone through that process again. Always end up cloning the repo locally, upload the folder I want to have in that repo to that cloned location, commit the changes and then push it.

Note that if you're dealing with large files, you'll need to consider using something like Git LFS.

Solution 5 - Github

For those still using master, this was changed to main

echo "# repo-name" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/username/repo-name.git
git push -u origin main

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLanie909View Question on Stackoverflow
Solution 1 - GithubJames GrahamView Answer on Stackoverflow
Solution 2 - GithubAdnan AzmeeView Answer on Stackoverflow
Solution 3 - GithubAchal KagwadView Answer on Stackoverflow
Solution 4 - GithubTiago Martins PeresView Answer on Stackoverflow
Solution 5 - GithubNMukamaView Answer on Stackoverflow