import fnmatch


def refineGitignore(contents, files):
    """
    Ignore only those files which are present in the repository
    """
    refinedContents = ""
    for exp in contents.split('\n'):
        for file in files:
            if fnmatch.fnmatch(file, exp):
                refinedContents += exp + '\n'
                break
    return refinedContents