Question

  • Project.git is a remote git repo that has a staging branch
  • Two developers are working on their own forks of project.git
  • Both developers only interact with staging

Common to both developers

# Developer 1 & developer 2 add staging as follows
$ git clone myForkOfProject.git
$ git remote add live project.git

Developer 2 working on docs

[master] $ git branch docs
[master] $ git checkout docs
[docs] $ git add README 
[docs] $ git commit -m "pushing to live's staging from local's docs works" README
[docs] $ git push live docs:staging

Developer 1 working on bugfix, wants to selectively merge docs

Developer 1 wants to see selectively merge files from docs into his local mybranch

[master] git branch mybranch
[master] git checkout mybranch
[mybranch] $  git fetch live staging

# Checks to see if anything changed
[mybranch] $  git status -s ./
[mybranch] $

# Doesn't know what to merge since diff, status shows no change 

# Where as if developer1 did
[mybranch] $  git pull live staging
[mybranch] $  git status -s ./
A  README

What developer1 actually wanted

What developer1 wanted to do is only to fetch the last changes in staging into the working directory without automatically adding README.

How do I pull/fetch so that git status -s ./ just downloads the changes

[mybranch] git *fetch changes from staging into mybranch 's working directory*
[mybranch] git status -s ./
[?] README
# This is what developer1 wants to see
# so that he can decide to 'git add README' manually
# here are the unsuccessful attempts to do the same

# Developer2 makes a commit, and does git push live docs:staging 
[mybranch] $ git fetch live staging
[mybranch] $ git pull live staging --no-commit --no-log --no-ff

The last option I have is to selectively call git rm --cached README, but I wonder if I'm missing something in the git fetch, git merge flow.

Was it helpful?

Solution

git status is for showing what's in your working directory. So after a git fetch, which doesn't change the working copy, of course you won't see anything.

git show is for showing changesets. So if you want to view the change before applying it, do git show (find the changes to examine with git log live..mybranch or the like; you could even use git log --patch to view the diffs inline with the commit notes).

However, in this workflow you say you specifically want to incorporate the changes into the working copy - but not to commit them.

You can do this in two steps: first, you git merge the changes in with yours. Then, you git reset [revision], giving the revision you were at before the merge.

This will leave you with no staged changes, an unmoved HEAD (you reset back to the state before the merge, so it's been effectively reversed), and a working copy containing all the modifications before you did the git merge.

git pull is just a shorthand for git fetch; git merge or git fetch; git rebase, depending on your settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top