Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push to specific folder on remote repository

How can I push to specific folder in the remote repository? I have the following structure on my local C drive:

myfolder/
    .git
    folder1
    folder2
    folder3
    folder4
    .gitignore

I executed git init command in this folder. After that I did git add . and then git commit -m "My first commit" Now I would like to push it to the VSTS remote repository that contains similar structure:

https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder

VSTS_folder/
   greenFolder
   redFolder
   blueFolder
   blackFolder
   yellowFolder
   .gitignore
   README.md

where VSTS_folder is the name of the repository. greenFolder, redFolder and yellowFolder have some code in there already. What I would like to do is to push my local stuff to blackFolder remote folder which is empty. I'm trying to avoid messing with the repo and pushing my stuff to the root. I was using git remote add origin https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder/blackFolder but that didn't work. What's the appropriate git command for achieving this? Thanks.

like image 873
TiredOfProgramming Avatar asked May 14 '18 20:05

TiredOfProgramming


People also ask

How do I push a specific directory in git?

Open Git Bash in that particular folder that you want to push. Type git remote add origin PASTE_SSH_KEY_OF_CREATED_REPO. Then type git push origin master –force (type 'main' in place of the 'master' if your default branch is master).

How do I upload a file to a specific folder in GitHub?

On your computer, move the file you'd like to upload to GitHub into the local directory that was created when you cloned the repository. Open Terminal . Change the current working directory to your local repository. Stage the file for commit to your local repository.


1 Answers

That's not how Git works. You have one repository called VSTS_folder. Whoever created that repo didn't understand what a Git repository is.

You need to clone the repository, which will give you a copy of the entire repo. Then you can add additional code to it.

If all of these folders contain totally independent projects that share nothing between them, then you should consider splitting them into separate repos.

You would also hugely benefit for sitting down and reading a Git tutorial to get a better understanding of these concepts.

like image 139
Daniel Mann Avatar answered Nov 07 '22 18:11

Daniel Mann