-2

I have an installation of a website with lots of subfolders like logs/, useruploads/,... that I don't need to track with Git.

I created a git repository on the server locally with

git init
echo 'userupload/*'>>.gitignore
echo 'logs/*'>>.gitignore
#....
git add .gitignore
git commit -a -m "initial .gitignore"
git add *
git comit -a -m "initial rest"

The only branch in this repo is called master, but I would like to rename it to release.

All solutions for renaming my master branch to release suggest to:

  • checkout master
  • rename it locally
  • and delete the old one

But this approach would cause me to lose all untracked files in my Git folder. Surely, there is a better approach... What should I do?

rubo77
  • 19,527
  • 31
  • 134
  • 226
  • It's not clear how you would lose your untracked files in the scenario you mention, or how your solution is different in any way. – Andrew C Nov 19 '14 at 02:17
  • My solution is different. There I don't checkout everything, rename it and delete the old branch. It is what I searched: only one command to rename the branch while leaving every thing else – rubo77 Nov 19 '14 at 06:06
  • you only have 1 branch so you are by default already checked out to it. And if you rename the branch there is nothing to delete. Right? – Andrew C Nov 19 '14 at 06:09
  • Try search yourself. The suggestions are different: they suggest to check out into a new location: https://www.google.com/search?q=rename+git+branch&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:de:official – rubo77 Nov 19 '14 at 06:19
  • In the end I found my solution. I guess it was hard to find, because I didn't know what you have to search for ( which is easy if you know the answer) – rubo77 Nov 19 '14 at 06:23
  • possible duplicate of [Rename local Git branch?](http://stackoverflow.com/questions/6591213/rename-local-git-branch) – Andrew C Nov 19 '14 at 06:34

1 Answers1

2

This worked for me:

git branch -m master release

from the manual:

-m, --move  
       Move/rename a branch and the corresponding reflog.

see: http://explainshell.com/explain?cmd=git+branch+-m+master+release


In my case after this, I want to commit the new branch remote to an existing repository, so I have to:

git remote add origin git@mygitserver.org:mygit.git
git push origin release

see https://help.github.com/articles/pushing-to-a-remote/

rubo77
  • 19,527
  • 31
  • 134
  • 226