简体   繁体   中英

how to push changes onto git repo ignoring extra folders and files in the local repo?

I have a local directory whose structure is something like :

  1. dir1
    • dir1.1
    • dir1.2
    • dir1.3
      • file1.3.1
      • file1.3.2
      • file1.3.3
  2. dir2
    • dir2.1
    • dir2.2
    • dir2.3

Structure of my github repository is :

  1. dir1
    • dir1.1
    • dir1.2
    • dir1.3
      • file1.3.1
      • file1.3.2
  2. dir2
    • dir2.1
    • dir2.2
    • dir2.3
      • file2.3.1
      • file2.3.2
  3. dir3
    • dir3.1
    • dir3.2
    • dir3.3

As it can be noticed, the github repository has some extra directories as well as some extra files in some directories. It may have some files missing as compared to local directory. So, I am looking for a way to push the changes of only those files which are already present in the repository. In other words, I want all other files/folders to be ignored. I don't want to add those new files/folders when I push. I only want the existing files to be synced.

I got this link which gives only suggests a way to ignore a folder. git to ignore a hidden directory in the local repo This doesn't solve my problem.

Please suggest how can I solve this problem. Thanks.

You could:

  • clone the GitHub repo separately
  • add in that local clone a remote referencing the path of your initial local repo (which has less folders)
  • fetch that remote
  • git add -u (add only the new/modified files, not the deleted ones)
  • push

That way, you import in your GitHub repo only what your local repo has added/modified.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM