Why GIT shows file as being added instead of renamed (creating duplicated file)?

I’ve been tasked with implementing a GIT workflow and also a release management process.

I’ve been looking into DataOps and this implementation seems to match what was requested to me.

The key points are:

  • Need 4 stable branches: main, staging, test and dev.
  • Need to be able to work on features completely independent. What I mean is that, if my coworker is working on feature001 and I’m working on feature002, then neither of the features should have to wait for the other feature in order to go to the higher environments.

However, something that I don’t understand is happening.

So far in my tests, these are the steps I took:

  1. I created a feature branch called feature/name001 where I create a file called text001.txt.

Then I push to the higher environments:

  • feature001 -> dev
  • feature001 -> qa
  1. I create a 2nd feature branch called feature/name002 where I create a file called text002.txt.

Similarly:

  • feature002 -> dev
  • feature002 -> qa
  • feature002 -> staging
  1. Created a hotfix branch called hotfix/bug001 where I create a file called hotfix001.txt.
  • hotfix001 -> main
  1. I then did a PR from staging -> main. This merged the file text002.txt to main.
  2. feature001 -> staging
  3. I then did a PR from staging -> main. This merged the file text001.txt to main.
  4. I create a 3rd feature branch called feature/name003 where I store the existing files (text001.txt, text002.txt) in a new folder called texts.
  5. feature003 -> dev

Here is where I see the issue.

I expected my dev environment to look something like this:

texts/text001.txt
texts/text002.txt
hotfix001.txt

Instead, this is what I see:

texts/text001.txt
texts/text002.txt
text001.txt
hotfix001.txt

Any idea on why this is happening?
Below is the python script I’m using to test this out. This script was made in 30min, so it’s not in it’s production stage at all!

# %%
import subprocess
import argparse


# %%
def create_feature_branch(branch_name: str):
    """
    Fetches updates, creates a new feature branch from origin/main and checks it out.

    Arguments:
        branch_name : Name of feature branch to create.
        message     : Initial commit message for feature branch creation.
    """
    try:
        subprocess.run(["git", "checkout", "main"])
    except e:
        Exception("Something went switching to main", e)

    try:
        subprocess.run(["git", "pull", "--rebase", "origin", "main"])
    except e:
        Exception("Something went wrong when rebasing from origin/main", e)

    try:
        subprocess.run(["git", "checkout", "-b", branch_name])
    except e:
        Exception("Something went creating new branch", e)


# %%
def deploy_to_environment(branch_name, env_branch):
    """
    Rebase feature branch from origin/main.
    Merges feature branch to specified env_branch.
    Pushes to origin/env_branch.

    Arguments:
    branch_name : Name of feature branch to be deployed.
    env_branch  : Name of base branch.
    """
    subprocess.run(["git", "checkout", branch_name])
    subprocess.run(["git", "pull", "--rebase", "origin", "main"])
    subprocess.run(["git", "checkout", env_branch])
    subprocess.run(["git", "pull", "--rebase", "origin", env_branch])
    subprocess.run(["git", "merge", branch_name])
    subprocess.run(["git", "push", "origin", env_branch])


# %%
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Automate GIT Release Workflow.")

    parser.add_argument("branch_name", type=str, help="Name of the feature branch.")

    deployment_environment = parser.add_mutually_exclusive_group(required=False)

    deployment_environment.add_argument(
        "--d",
        "--dev",
        "--deploy-dev",
        action="store_true",
        help="Deploy to dev branch.",
    )

    deployment_environment.add_argument(
        "--t",
        "--tst",
        "--deploy-tst",
        action="store_true",
        help="Deploy to tst branch.",
    )

    deployment_environment.add_argument(
        "--s",
        "--stg",
        "--deploy-stg",
        action="store_true",
        help="Deploy to stg branch.",
    )

    deployment_environment.add_argument(
        "--p",
        "--prd",
        "--deploy-prd",
        action="store_true",
        help="Deploy to prd branch.",
    )

    args = parser.parse_args()

    if not (args.d or args.t or args.s or args.p):
        create_feature_branch(args.branch_name)
        print("Created and switched to branch", args.branch_name)
    else:
        if args.d:
            deploy_to_environment(args.branch_name, "dev")
            print("Deployed", args.branch_name, "to dev environment.")
        if args.t:
            deploy_to_environment(args.branch_name, "test")
            print("Deployed", args.branch_name, "to tst environment.")
        if args.s:
            deploy_to_environment(args.branch_name, "staging")
            print("Deployed", args.branch_name, "to stg environment.")
        if args.p:
            deploy_to_environment(args.branch_name, "main")
            print("Deployed", args.branch_name, "to prd environment.")

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật