0

I'm new to programming in general. I understand the basic functions of git such as push, fetch. commit, add, etc.

I want to know if it's possible to add single files to a git repo. I'm learning js and the way I have it set up is by topics I want to learn, categorized by folders on my local drive:

-topic
--arrays
--async_promise
--backend
--api
--etc.

Within each folder, I have html/js practice files and I want to commit them to git just so I can show future employers that I am coding everyday.

On github, I want to commit and push these files to one folder under one repo such as web-dev/practice. Can I do this with git or is this not best practice?

I tried using fetch but it fetched every single file into one topic folder onto my local drive.

Julian
  • 411
  • 4
  • 18
  • 3
    You don't push/fetch files you push/fetch commits. It soulds like you want seperate repos for each of the folders. – user1937198 Apr 11 '21 at 18:27

1 Answers1

1

tl;dr What is pushed is what is in your local repository. If you want to push something different, you have to change your local repository.

Pushing and pulling just copies commits (and their content). The content of the commit cannot be changed by a push or pull, that would change its commit ID which is fundamental to how Git works.

You also cannot pick and choose which commits are pushed. If you push a branch, its entire history must also be pushed. This is also fundamental to how Git works.

If you want to push only certain files, you have to commit only those files. If you want to push only commits to certain directories, that suggests you should turn each of those directories into their own repositories.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • Can you please elaborate on the last paragraph starting with "if you want to push only commits..."? Like folder directories? If I turn those directories into their own repos, then I would have many repos. I kind of just want one repo to be a "practice/learning" repo because it would only contain individual files and is not project-based. What's best practice? – Julian Apr 11 '21 at 18:37
  • 1
    @Julian Generally it's one repo per project. In your case your web dev practice is the project. Make a repo called `web-dev-practice` and put your practice directories at the top level. `web-dev-practice/arrays`, `web-dev-practice/backend`, etc. Then you commit, push, and pull as normal. – Schwern Apr 11 '21 at 18:45