How can I create a new remote branch by a commit with no changes?
When I create a new branch and push it to my git repo, the new branch is lined up with master branch because I did not make any changes. This is how I did it.
git checkout -b newbranch
git push -u origin newbranch
I want to create a branch with a commit so that others can see a commit message that a branch was created. But, I do not want to make any changes in this commit. Basically, my new branch should be ahead of master by 1 but files are identical with those in master.
How can I do this? I tried git commit -m "created branch newbranch"
before the git push
, but git told me that there is nothing to commit.
Solution 1:
I guess --allow-empty
is what you are looking for. Also see here
git checkout -b new-branch-name
git commit --allow-empty -m "message"
git push <remote> HEAD:branch-name