Using git to track remote branch without merging

I use git to track content that has been modified by some people and shared read-only with others. Readers may make changes from time to time, but they will not generally be.

I want to allow git to “writers” to reinstall repelled branches **, if necessary, and to ensure that “readers” never accidentally get merged. This is usually fairly easy.

git pull origin +master 

There is one case that seems to be causing problems. If the reader makes a local change, the command described above will merge. I want the attraction to be fully automatic if the reader hasn’t made local changes, and if they made local changes, he should stop and ask for input. I want to track any upstream changes, being careful when merging subsequent changes.

In a way, I really don't want to pull. I want to track the master branch accurately.


** (I know that this is not the best practice, but in our case it seems necessary: ​​we have one main branch that contains most of the work and some topic branches for specific clients with minor changes that need to be isolated. It seems easier Often often reinstall to keep the themes updated.)

+4
source share
6 answers

You are looking for the git-fetch command.

+7
source

You may also find git pull --rebase useful.

Update: --rebase can be --rebase by default by setting branch.<name>.rebase = true to separate branches. Setting branch.autosetuprebase = true defaults to setting this in new branches, although existing branches will need to be updated manually. Or you can always set the --rebase value by setting pull.rebase = true globally.

+4
source

What about:

  git pull --ff-only origin master 

I often use this. Unfortunately, as pointed out in the description of richard-hansen @, this does not work as an alias:

 [alias] pull = pull --ff-only 
+2
source

Since you do not want manual merging using reader readers, you can write a hook to check what happened and request the user:

http://git-scm.com/docs/githooks

I would still just recommend getting and reading information about my merges or repositories locally. This is a simpler solution to your problem.

0
source

Git 2.0 (Q2 2014) will add commit b814da8 a config push.ff :

 pull.ff:: 

By default, Git does not create an additional merge commit when merging a commit that is a descendant of the current commit. Instead, the tip of the current branch is quickly redirected.

  • When set to false, this variable tells Git to create an additional merge in this case (which is equivalent to providing the -no-ff option from the command line).
  • If only a value is set, only such fast merges are allowed (equivalent to providing the --ff-only option from the command line).
0
source

I think you need a workflow with two branches. The combined local branch (master) and the remote read-only tracking branch (remote).

Using dual remotes on the main branch allows you to continue working and update the remote project. Your local changes and merged remote changes can be transferred to the local git server.

  git push localserver master 

Source patches can be created and updated in your branches of remote tracking and submitted to the project.

A separate tracking branch for the remote read-only allows you to prepare corrections and commits for the upstream to the remote project.

 # Master branch is merge of local changes, and remote changes git checkout master git pull -m origin master # Set up a local tracking branch for the 'read-only' remote. git checkout -b remote remote master # Start reviewing changes between the two branches. git diff --name-status ..master 

If you want to go back to the patch, then diff from master..remote can be used to determine the fix for your remote read-only branch.

 git diff master..remote -- files >patch git checkout remote patch -p1 <patch git commit -m "Your patch" git format-patch -1 

Send the formatted patch file to the remote project. If you need to make changes and reinstall the remote project, you can perform this work in your remote tracking branch until it is approved.

(Setting up a dual git console involves editing .git / config and is explained elsewhere)

0
source

Source: https://habr.com/ru/post/1313015/


All Articles