[git] How do I add files and folders into GitHub repos?

I created an account on GitHub — I'm new on it — and I'm facing a problem with adding files. I have added readme.txt. Also, I have 3 other PHP files and a folder including images.

How do I add the files and folder? I tried it with git pull because git push origin -u master showed me an error.

This question is related to git github

The answer is


When adding a directory to github check that the directory does not contain a .git file using "ls -a" if it does remove it. .git files in a directory will cause problems when you are trying to add a that directory in git


Check my answer here : https://stackoverflow.com/a/50039345/2647919

"OR, even better just the ol' "drag and drop" the folder, onto your repository opened in git browser.

Open your repository in the web portal , you will see the listing of all your files. If you have just recently created the repo, and initiated with a README, you will only see the README listing.

Open your folder which you want to upload. drag and drop on the listing in browser. See the image here."


Simple solution:

git init
git add =A
git commit -m "your commit"
git push -u origin master

if you want add folder to existing repo ..then add folder to local project code

git rm --cached ./folderName
 git add ./folderName

after that

git status
git commit -m "your commit"
git push -u origin master

I'm using VS SSDT on Windows. I started a project and set up local version control. I later installed git and and created a Github repo. Once I had my repo on Github I grabbed the URL and put that into VS when it asked me for the URL when I hit the "publish to Github" button.


For Linux and MacOS users :

  1. First make the repository (Name=RepositoryName) on github.
  2. Open the terminal and make the new directory (mkdir NewDirectory).
  3. Copy your ProjectFolder to this NewDirectory.
  4. Change the present work directory to NewDirectory.
  5. Run these commands
    1. git init
    2. git add ProjectFolderName
    3. git commit -m "first commit"
    4. git remote add origin https://github.com/YourGithubUsername/RepositoryName.git
    5. git push -u origin master

Note that since early December 2012, you can create new files directly from GitHub:

Create new File

ProTip™: You can pre-fill the filename field using just the URL.
Typing ?filename=yournewfile.txt at the end of the URL will pre-fill the filename field with the name yournewfile.txt.

d


You need to checkout the repository onto your local machine. Then you can change that folder on your local machine.

git commit -am "added files"

That command will commit all files to the repo.

git push origin master

that will push all changes in your master branch (which I assume is the one you're using) to the remote repository origin (in this case github)


If you want to add an empty folder you can add a '.keep' file in your folder.

This is because git does not care about folders.