32

I cloned a repository to my desktop machine using git clone sshurl. As expected, this created a folder in my desktop.

Now, instead of a single file, I want to push a whole folder into git. For example, the folder that I cloned is named project_iphone. Now I add another folder called my_project into project_iphone. The my_project folder contains lots of files and folders as well.

My question is, how should I push my_project folder to the server?

Step-by-step instructions would be helpful.

Thank You.

Bob Gilmore
  • 12,608
  • 13
  • 46
  • 53
da32
  • 703
  • 1
  • 9
  • 18

4 Answers4

51

You need to git add my_project to stage your new folder. Then git add my_project/* to stage its contents. Then commit what you've staged using git commit and finally push your changes back to the source using git push origin master (I'm assuming you wish to push to the master branch).

Gavin
  • 1,223
  • 15
  • 20
  • 1
    it works nicely.....now I've push a folder to git...how do i remove the folder? tried git rm but failed... – da32 Mar 26 '13 at 00:14
  • 2
    never mind already..just needed to add -r..if not can't delete folder...thx for help anyway... – da32 Mar 26 '13 at 09:42
  • @da32 folders are not versioned in git, just files. It's by making a folder empty that you virtually delete it. – Sandburg Apr 03 '23 at 09:49
1

You can't push a new empty folder. First you must create at-least one new file in the new folder and then you can add, commit and push it.

Omidreza Bagheri
  • 781
  • 1
  • 11
  • 22
1

In order to push any folder from git bash, you have to make a single file it could be anything text or etc. If you try to push an empty folder your git bash will not give you an error but when you refresh your GitHub you will not see that folder, so in order to push any folder just make a single file and push, after that you can add your stuff and delete the previous file(if you want to).

to push follow the below commands

  1. -git add (folder name) -git add . (in order to push everything) -git commit -m "anything" (to keep track of your changes)

if not added remote origin then do this

  1. -git remote add origin (your repo link) then to push files -git push -u origin main

to push on the master branch

  • -git push -u origin master

look if you have already created a repo then do

  • -git push -u origin master
Kumawat Lalit
  • 410
  • 4
  • 8
0

You can directly go to Web IDE and upload your folder there.

Steps:

  1. Go to Web IDE(Mostly located below the clone option).
  2. Create new directory at your path
  3. Upload your files and folders

In some cases you may not be able to directly upload entire folder containing folders, In such cases, you will have to create directory structure yourself.

Chan Gaikwad
  • 171
  • 3
  • 14