1

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.

  • How is it that the remote repo has `dir3`, `file2.3.1`, and `file2.3.2`, but your local copy has none of those files? – Gino Mempin Jul 29 '17 at 23:45
  • Actually, I want to sync two versions of a package. The two versions have similar folder structure, and some common files. Other than that, both may have some unique extra files. So, the local repo is the one I pulled from version1 and I want to sync the changes in common files of version2 (remote github repo). – Piyush Jain Jul 30 '17 at 06:57

1 Answers1

0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250