TiredOfProgramming
TiredOfProgramming

Reputation: 855

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.

Upvotes: 12

Views: 49912

Answers (3)

Rick Lockyer
Rick Lockyer

Reputation: 41

git add .\<folder name>
git push

That should be all you need. I just did it

Upvotes: 3

Marina Liu
Marina Liu

Reputation: 38136

For Git version control system, it push changes to remote repo by branches (not by folders as svn VCS).

So you need to move the local stuff into blackFolder, and pull changes from remote repo (VSTS git repo), and finally push the branch into VSTS git repo.

Detail steps as below:

# In your local git repo
rm -Rf .git #it's uncessary to commit at first in your local repo
git init
git remote add origin https://helloworld.visualstudio.com/VSTS_folder/_git/VSTS_folder -f
mkdir blackFolder
mv * blackFolder
mv .gitignore blackFolder
git pull origin master
git add .
git commit -m 'add local stuff to remote repo blackFolder'
git push -u origin master

Now the local stuff are push to the VSTS git repo under blackFolder.

Upvotes: 5

Daniel Mann
Daniel Mann

Reputation: 59055

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.

Upvotes: 11

Related Questions