githubteacher / github-for-developers-sept-2015

practice repo for the Sept 29-30 GitHub for Developers class
12 stars 36 forks source link

How to add a new folder in a branch and push to "origin"? #689

Closed kaiyuan01 closed 8 years ago

kaiyuan01 commented 8 years ago

:+1:

saranicole commented 8 years ago

You can use the git add command for a directory as you can for a file: git add mydirectory

http://git-scm.com/docs/git-add

Then you will need to commit as usual: git commit

Finally push: git push -u origin mybranch

jaw6 commented 8 years ago

Git, due to its design, doesn't track empty folders -- git only tracks files. Files can be inside folders, but an empty folder, by itself, is "invisible" to Git.

In software development, it's common for projects to need an empty folder to be part of the project (a log directory, say, where the program can write log files, might need to exist on disk, even if we don't actually ever want to track log files in version control).

The convention for managing this in Git is to create a hidden file inside the folder you want to track. Files beginning with a "." (a period or dot) are treated as hidden files, so the convention is:

mkdir folder-to-track
touch folder-to-track/.gitkeep
git add folder-to-track
saranicole commented 8 years ago

Thanks @jaw6 for the clarification