Git push to specific folder on remote repository

27,101

Solution 1

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.

Solution 2

git add .\<folder name>
git push

That should be all you need. I just did it

Solution 3

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.

Share:
27,101
TiredOfProgramming
Author by

TiredOfProgramming

Updated on August 16, 2020

Comments

  • TiredOfProgramming
    TiredOfProgramming almost 4 years

    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.

  • Chandni
    Chandni over 3 years
    I have iOS project and when I am pushing my code it is saying repo size exceeds 100mb. Now I added pods in gitignore still getting same message. Can you please suggest how can I push my complete code
  • Daniel Mann
    Daniel Mann over 3 years
    @Chandni That is a totally unrelated question. If you have a new question, please ask a new question.