Repo specific ignore files in git

前端 未结 4 2023

Is it possible to have repo specific .gitignore files? Eg:

[origin] .gitignore:

  • foo1.*
  • foo2.*

[another] .gitignore:

    <
4条回答
  •  一整个雨季
    2020-12-18 11:24

    My Situation:

    Having a file named alex.todo which contains my personal notes about the project. I have two remote repo to push(origin and alex). One for sharing the code with other developers(I use .gitignore to exclude the alex.todo file), one just for backing up this project which is ok to preserve the alex.todo file.

    My final solution:

    Using a temp branch to push the alex.todo to the backup repo.

    # Step 1
    git checkout -b alex # 'alex' or whatever branch name you prefer
    
    # Step 2
    # now you can edit your .gitignore to include your 'alex.todo' file
    
    # Step 3
    git add . && git commit -m 'commit some ignore files'
    git push alex alex:master # git push  :
    
    # Step 4
    git checkout master  # return to branch master and do any editings(commits)
    
    # Step 5
    # make sure branch alex is in sync with master whenever you want to push the project to the backup repo
    git checkout alex
    git merge master # .gitignore will not automatically be included for commit unless specifically added
    # now you can repeat step 3 to push the project to the backup repo
    

提交回复
热议问题