Git: Local-tracking, add new branch?

I am trying to clean up my git repository and

  1. Create a new branch that mirrors my production (master) branch.
  2. Remove any unnecessary branches, remote or local.
  3. Make my local branches local-tracking branches (idk if i need to do this, benefits?)
  4. Have a branch for each stage of my workflow i.e. one branch for local & dev (dev), 1 branch for staging (staging), and 1 branch for production (production). Local and dev can share the same working branch, but separate branches for staging and production.

From the command line you can see my environment.

  • git-clone fatal, permission denied
  • Github Service Hooks: post-receive via PHP
  • Git lfs (Large File Storage) says lfs managed files are modified after a git lfs pull
  • squash commits after rebasing
  • Are multiple histories in a git repository likely to cause future issues?
  • Git - fatal: unknown error occured while reading the configuration files
  • $ git remote
    dev
    origin
    production
    staging
    
    $ git branch -r
    dev/dev
    origin/HEAD -> origin/master
    origin/dev
    origin/master
    production/master
    wpengine-findcra/master
    
    $ git branch -vv
    dev                   xxxxxxx <comment>
    *master               xxxxxxx [origin/master] <comment>
    production/staging    xxxxxxx [remotes/production/master] <comment>
    staging/master        xxxxxxx <comment>
    

    I have 4 locations I work out of. Code flows from 1 to 4.

    1. my local machine
    2. development server
    3. staging server
    4. production server

    I want to add a new branch specifically for the staging server, and right now I want it to mirror the production (master) branch. But I run into this error and I don’t know what to do.

    $ git checkout master
    $ git branch staging
    error: there are still refs under 'refs/heads/staging'
    fatal: Failed to lock ref for update: Is a directory
    

    My code is up to date under origin/master and dev/dev.

  • `git blame/annotate`: terminate on merge commits
  • Creating a SSH key with ssh-keygen does not create the .ssh folder
  • Tracking changes in Visual Studio
  • How to import svn branch to git with trunk history
  • git init is creating in incomplete .git folder - how do I fix it?
  • Commit a change to more than one branch in Git
  • One Solution collect form web for “Git: Local-tracking, add new branch?”

    If you have a branch with a name that contains a slash, git will create (in .git/refs/heads) a directory named like the name of your branch until the slash. In that directory it will place the refs for the branch itself. So the directory .git/refs/heads/staging/ exists and contains a file “master” due to your branch staging/master.

    When you try to create the branch “staging”, git will try to create the file .git/refs/heads/staging. As this already exists but is a directory, this will fail. Thus you cannot have two branches with these names in your repository.

    In more recent versions of git the error message will look like this:

    fatal: cannot lock ref 'refs/heads/staging': 'refs/heads/staging/master' exists; cannot create 'refs/heads/staging'
    
    Git Baby is a git and github fan, let's start git clone.