gitfileoverwritegit-untracked

Overwrite files in git repo


A code project is sent to us without version control. We have turned its initial version into a git repository and made a dev branch to make some changes. Now a new version has been delivered (again without version control, just the files with changes), so the question is:

How do we correctly integrate this new version into the main branch of our repository, and then pull the changes into the branches we made?

I have tested just overwriting all the files within the repo (main branch), but git status then reports all files and all lines as modified, so I hesitate to do add/commit.

What I would like to see is the changes between the delivered versions reflected in the repo as if we would have edited the existing files and then added/committed the changes.


Solution

  • How do we correctly integrate this new version into the main branch of our repository and then pull the changes into the branches we made?

    As you have already done, you could checkout your main branch, overwrite the interested files with the new versions, stage the changes, and finally commit.

    # while on the main branch with all the changes uncommitted
    
    # staging the changed files
    git add <file1>, ..., <fileN>
    
    # committing the changes from the new version
    git commit -m "new version blah bla blah"
    

    At this point, if you want to see the new changes reflected in your dev branch, you could either:

    1. Rebase dev on top of main.
    # selecting the dev branch
    git checkout dev
    
    # rebasing the dev branch on top of main's head commit
    git rebase main
    
    1. Cherry-pick the new commit from main into dev
    # selecting the dev branch
    git checkout dev
    
    # creating a new commit in dev with the changes from main's head commit
    git cherry-pick main
    

    This is just a suggestion, but a significant improvement in your workflow could be to host the repository you've created on a platform like GitHub, BitBuket or similar. Like so, the people from the other team could make their changes on the same project/repository, easing the collaboration between your team and theirs.

    Once the repo has been set up on a hosting service, every member of both teams can download a copy of the repository and work on the project locally. As soon as someone has produced some meaningful changes, they could push their commits to the remote repository (possibly on a specific or personal branch), sharing their work with the other members.

    If some of you are new to collaborating with version control tools, here are some links that could help to set up a bare skeleton for your workflow. Keep in mind that these are very basic guides. They're just meant to start with: