I am currently using local repo on windows to save my code. It basically keeps tracks of all the files and folder in the working directory. I now want to also push it to github every time I commit locally for backup purposes but exclude public/images
folder since there is no need for images to be on github. I do git commit -a -m "this locally commits all the files and folder including images"
for local repo so what can I do to push it to github but exclude a specific folder public/images.
The way I push to my github is
git remote add origin
git remote -v
git push origin master
push
and pull
synchronize the commit histories of a repository and its remotes. There is no way to filter out certain files or directories (how should this deal with, for example, commits that affect files in ignored and non-ignored directories?).
If that is what you want, it sounds like public/images
could be an entirely different repository. That could either be a git submodule (meaning the main repository would still keep track of commit IDs of the submodule in its history, but the submodule itself would not need to be published) or by initializing a new repo in public/images
and adding it to .gitignore
for the main repo as the other answers suggest.
You can create a file called .gitignore
in your repo root directory and inside type the directories or files that you dont want to push.
eg)
#media
public/images
You have to use .gitignore file in your project folder. For your case you can use the following pattern:
*public/*
This will exclude all files in the folder "public".
Or to be more specific:
***/public/images*
This will exclude folder "images" in parent folder "public".
Please checkout documentation: gitignore - Specifies intentionally untracked files to ignore
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.