How to create branch-specific files on GitHub

这一生的挚爱 提交于 2019-12-05 06:39:48

Let's say project is a name of the branch to be merged, and README.md is a name of the file that keep branch specific information.

I would suggest the following steps:

  1. Merge project branch, but make sure changes are not committed, and not fast-forwarded

    $ git merge --no-commit --no-ff project
    
  2. Unstage README.md file and checkout its current branch version

    $ git checkout HEAD -- README.md
    
  3. Complete merge

    $ git commit
    

Also, it makes sense to install merge driver that will keep branch specific version of a file in case of merge conflict. In such case, you will never need to resolve conflicts in branch specific files manually.

Such merge driver is usually called ours and defined as:

$ git config --global merge.ours.driver true

Now, you can specify in .gitattributes file, when this merger should be used.

In our case, it is needed to add the following rule to .gitattributes and commit it:

README.md merge=ours

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!