2

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.

CookieEater
  • 2,237
  • 3
  • 29
  • 54
  • Why do you need to do this? They should be able to see in a graph of the repository's history when the branch was created. It also means that, further down the line, if the branch is deleted, you'll have a residual empty commit on your master branch that just mentions a defunct branch. – Will Vousden Jan 18 '14 at 21:36
  • You can always check that remote branch is created with `git branch -r` command and look if the branch is in the list. – antonv Jan 18 '14 at 21:42
  • possible duplicate of [How to commit no change and new message?](http://stackoverflow.com/questions/12470029/how-to-commit-no-change-and-new-message) – Maic López Sáenz Jan 19 '14 at 21:56

2 Answers2

5

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
alper
  • 2,919
  • 9
  • 53
  • 102
Adam Adamaszek
  • 3,914
  • 1
  • 19
  • 24
0

If I understood you correctly what you want to achieve is unfortunately impossible. When you create a branch you essentially create a commit that reference to other commit. If you don't want to change anything in branch please add a file and commit and then remove that file in next commit.