1

In my project, I have many staged files which are inline configured at many places with my localhost settings which I am not willing to push to server. and the server files has settings of external server which I am not willing to pull.

So actually, I am looking for a way where I can partially push/pull the changes to/from the server, respectively.

I think I am missing some basic concepts of dealing with Git here. So, I will explain how I am managing things now:

I keep two directories of same project, one for to communicate to git (git directory) and other where I work (working directory). So, whenever I do changes in working directory which are ready to commit, I do the following:

  • Pull server changes in git directory
  • Compare working directory with git directory using third party tools like Beyond Compare
  • While comparing step by step, I can easily solve any merge conflicts and insert partial necessary code in working directory from git directory.
  • Push the new git directory changes to server.

Pros:

  • There will be no scenario of merge conflicts as the git directory has only the code from server.
  • I will have a extra backup of my project.
  • Can easily manage push/pull of partial code to/from server, respectively.

Cons:

  • Need to manage code in two directories i.e git directory and working directory.
  • Sometimes while comparing working directory with git directory, there is a high possibility of missing some files to compare.

I don't know whether I am doing this right or not as you can see I am using git only to push or pull the changes.
Please let me know whether I can do the same using git completely without depending on maintaining two directories or using Beyond compare like tools.

Kara
  • 6,115
  • 16
  • 50
  • 57
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
  • This sounds like a total hack, and it circumvents what the Git framework provides for you. Git already has something called tracking branches, which are like your own local copy of what the remote looks like. You should just have one local location for your repository, and sync all branches from there. – Tim Biegeleisen Jan 25 '16 at 07:43
  • @TimBiegeleisen I would be happy if you enlighten me on how to do that. at least providing a link would be suffice for me. – Mr_Green Jan 25 '16 at 07:46
  • Please work through a few Git tutorials, like the one [here](http://git-scm.com/docs/gittutorial). Based on your rep, I'm guessing you are an experienced engieneer who however is fairly new to using Git. The process you describe is similar to what will happen with Git, but there is only one working directory which syncs with the remote. – Tim Biegeleisen Jan 25 '16 at 07:49
  • @TimBiegeleisen I do know the basics of git at a level where I can survive (as you can see what I am doing above). Though the way I am doing is working fine, I am taking out some time to make it more better by asking here. I will definitely look for the link which you mentioned. thanks. – Mr_Green Jan 25 '16 at 07:58

2 Answers2

1

Your approach is sensible, in that it keep potentially sensible information in a non-git folder (no risk to accidentally push from there)

One possible simpler modus operandi though:

When you pull from git server into git folder, you can then start adding incrementally your work from "working" with git add -p (or lauch an interactive staging)

The trick is to do so from the git repo, but referring to the working folder as the current working tree (just for that add -p command)

cd /path/to/git/repo
git --work-tree=/path/to/working add -p .

You will then decide what to add on a hunk by hunk basis.

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

====================== UPDATED 25 Jan ========================
You can define multiple remotes for your git repository for pull/push. It's as simple as

git remote add [name] [repo-url] .

When staging and commiting files, you choose the files you want to push to remote_one, then

git push remote_one branch_name.

and the same process for remote_two and ... . The same is true for pulling from remotes, too. Take a look at this question.


You can create .gitignore file for excluding files that should not be tracked by git, like the configuration files. Usually most IDEs support some kind of git plugin which can create this file, based on your project type. For more information take a look at the git documentation.

Community
  • 1
  • 1
Farhad
  • 12,178
  • 5
  • 32
  • 60
  • I don't think this really addresses what the OP is asking. – Tim Biegeleisen Jan 25 '16 at 07:47
  • You can always in/exclude file types that are indicated in the gitignore file, If that's what you mean. – Farhad Jan 25 '16 at 07:49
  • In a staged file, I have some local settings which I am not willing to push but I am willing push the other changes, **partial push**. So, I am asking whether this is possible in git or not. – Mr_Green Jan 25 '16 at 07:52
  • @FarhadFaghihi you still didn't get it. I need to partial push/pull changes related to a file (not files). – Mr_Green Jan 25 '16 at 08:03
  • Git pushes and pulls file in one piece. To the best of my knowledge, It can't be done with the regular git workflow. Sorry dude. – Farhad Jan 25 '16 at 08:11