Creating a new empty branch for a new project

前端 未结 8 2062
你的背包
你的背包 2020-11-28 00:10

We are using a git repository to store our project. We have our branches departing from the original branch. But now we want to create a small new project to track some docu

8条回答
  •  隐瞒了意图╮
    2020-11-28 00:46

    The correct answer is to create an orphan branch. I explain how to do this in detail on my blog.(Archived link)

    ...

    Before starting, upgrade to the latest version of GIT. To make sure you’re running the latest version, run

    which git
    

    If it spits out an old version, you may need to augment your PATH with the folder containing the version you just installed.

    Ok, we’re ready. After doing a cd into the folder containing your git checkout, create an orphan branch. For this example, I’ll name the branch “mybranch”.

    git checkout --orphan mybranch
    

    Delete everything in the orphan branch

    git rm -rf .
    

    Make some changes

    vi README.txt
    

    Add and commit the changes

    git add README.txt
    git commit -m "Adding readme file"
    

    That’s it. If you run

    git log
    

    you’ll notice that the commit history starts from scratch. To switch back to your master branch, just run

    git checkout master
    

    You can return to the orphan branch by running

    git checkout mybranch
    

提交回复
热议问题