Git: Local tracking, add a new branch?

I am trying to clear the git repository and

  • Create a new branch that reflects my production (main) branch.
  • Delete unnecessary branches, remote or local.
  • Create local branches of local branching (idk, if I need to do this, benefits?)
  • You have a branch for each stage of my workflow, that is, one branch for local and dev (dev), 1 branch for setting (stage) and 1 branch for production (production). Local and dev can use the same working branch, but separate branches for production and production.

At the command line you can see my environment.

$ 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 from which I work. The code changes from 1 to 4.

  • my local machine
  • development server
  • staging server
  • production server

I want to add a new branch specifically for the intermediate server, and now I want it to reflect the production (master) branch. But I came across this error , and I do not 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 updated at the beginning of / master and dev / dev.

+5
source share
1 answer

If you have a branch with a name containing a slash, git will create (in .git/refs/heads ) a directory with the name, like the name of your branch, before the slash. This directory will contain links for the branch itself. So the .git/refs/heads/staging/ directory exists and contains the "master" file because of your staging/master branch.

When trying to create a "waging" branch, git will try to create a .git/refs/heads/staging file. Since it already exists, but is a directory, this will fail. Thus, you cannot have two branches with these names in your repository.

In later 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' 
+7
source

Source: https://habr.com/ru/post/1236250/


All Articles