Search code examples
gitgit-push

How to push part of directories into GitHub and remain others locally?


There are many files in my local directory test.

ls  test
test1   test2   test3  test4 test5 tes6 test7 

To push all the files in test

cd test
sudo git init
git add *
git commit -am  "push"
git push -f  origin master

All files from file1 until file7 pushed into my github repository.
Now how to push only test1 test4 test5 test7 into my github repository?

Here is my wordpress directory.

ls /var/www/html/wp
index.php        wp-blog-header.php    wp-includes        wp-signup.php
license.txt      wp-comments-post.php  wp-links-opml.php  wp-trackback.php
readme.html      wp-config.php         wp-load.php        xmlrpc.php
wc               wp-config-sample.php  wp-login.php
wp-activate.php  wp-content            wp-mail.php
wp-admin         wp-cron.php           wp-settings.php

All directories pushed instead of wp-content.


Solution

  • If those folders are empty, you need to add a file (any file) in it.

    For instance, a .gitkeep empty file.

    If they are not empty, the a git add test1 test4 test5 test7 is enough.
    Or:

    • Add the other folders (you don't want to add) in a .gitginore.

      test10/
      
    • Then you can git add . (no need for *), commit and push.

    That will add everything except the folder you don't want.

    Avoid git add *, as the '*' is interpreted by the shell.