bighelpdiscord
bighelpdiscord

Reputation: 111

Pushing a subdirectory and its contents to an established remote repo

I'm having trouble understanding how to git push a sub-directory of a local repo directory to Github. For example, I have an established git connection with Gibhub that contains only the main directory and the .py script inside (project/script.py). I added a 'db' sub-directory with a single .json file inside (project/db/list.json). I want to push project/db/list.json to my Github to the already established directory (project) on the same branch.

Do you I need to git init in the sub-directory or is it possible to simply push the actual sub-directory?

Upvotes: 1

Views: 3084

Answers (2)

Na1k
Na1k

Reputation: 36

In git you have a specific workflow to follow.

  1. Do work in your git-project
  2. Add files to the staging area
    • git add
  3. Commit the staged files to the local repository
    • git commit
  4. Pulling the remote repository
    • git pull
  5. Pushing your local repository to remote
    • git push

To answer your question: After changing files in your project, you can add specific files to the staging area. Only these staged changes get commited and pushed in the following steps.

Like larsk pointed out, the Git book contains very helpful and further information about git.

Upvotes: 1

VonC
VonC

Reputation: 1329722

You always push the all repository, meaning all the commits you have done since your last push.

One of those commits might involve files from one folder, but that is not mandatory: you cam make a commit with changes from multiple folders.

In your case, as commented, add and commit your subfolder content. You can then push it.

Upvotes: 1

Related Questions