Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push a new folder (containing other folders and files) to an existing git repo?

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.

like image 922
da32 Avatar asked Mar 25 '13 09:03

da32


People also ask

How do I push a new folder to an existing GitHub repository?

To push a new project to an existing GitHub repository, follow these steps: Create a GitHub repository for the existing project. Copy the GitHub URL for the new repo to the clipboard. Perform a git init command in the root folder of the existing project.

How do I add an entire folder in git?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.


2 Answers

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).

like image 180
Gavin Avatar answered Oct 13 '22 00:10

Gavin


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.

like image 23
Omidreza Bagheri Avatar answered Oct 13 '22 00:10

Omidreza Bagheri