简体   繁体   English

git 分支未显示所有分支

[英]git branch is not showing all the branches

/opt/lampp/htdocs/drupal-8.4.0$ git branch /opt/lampp/htdocs/drupal-8.4.0$ git 分支

I have installed drupal in my system,I want to switch to other branch but when used git branch is not showing other branches !我已经在我的系统中安装了 drupal,我想切换到其他分支,但是使用 git 分支时没有显示其他分支!

执行git branch -av显示所有远程和本地分支。

It might be a possibility that you don't have those branches locally.您可能在本地没有这些分支机构。

to pull all additional branches,拉出所有额外的分支,

git fetch

it should be like this not like above它应该是这样的,而不是像上面那样

git fetch --all or git fetch <branch Name>

then you can use either checkout or branch to check if it shows然后您可以使用checkoutbranch来检查它是否显示

git checkout name-of-the-branch
git branch

使用git branch -a查看 repo 中的所有分支,然后您可以使用git checkout branchname签出到相应的分支

git branch --all git 分支--全部

this git command will display all the branches.这个 git 命令将显示所有分支。

This can happen if your repo has 0 commits.如果您的仓库有 0 次提交,就会发生这种情况。 If you make a commit, your current branch will appear when you do: git branch .如果您进行提交,您的当前分支将在您提交时出现: git branch

首先执行 git fetch 以从远程提取额外的分支信息

I had a basic testing on this.我对此进行了基本测试。 The script: git branch -r is relying on remote reference of local git repository.脚本: git branch -r依赖于本地 git 存储库的远程引用。

To get the remote branches, the best practice would be:要获得远程分支,最佳做法是:

  1. Firstly, execute the script: git pull / git fetch /... to sync latest remote repository data into your local repository;首先,执行脚本: git pull / git fetch /... 将最新的远程仓库数据同步到本地仓库;

  2. Then execute the script: git remote prune origin to clean up those non-existed git branches in your local git repository;然后执行脚本: git remote prune origin清理本地git仓库中那些不存在的git分支;

  3. Finally, execute the script: git branch -r最后执行脚本: git branch -r

do git branch -a it will give you all the branches in the remote.执行git branch -a它将为您提供远程中的所有分支。 another option git fetch --all Then if you want to change or what operation you want to give you can do.另一个选项git fetch --all那么如果你想改变或者你想给什么操作你可以做。 example - if you want to change branch then git checkout <branch name from shown branches>例子 - 如果你想改变分支然后git checkout <branch name from shown branches>

  • Open git bash打开 git bash

  • Run the following command in the right git project folder:在正确的 git 项目文件夹中运行以下命令:

    git config remote.origin.fetch "+refs/heads/ :refs/remotes/origin/ " git config remote.origin.fetch "+refs/heads/ :refs/remotes/origin/ "

  • Fetch拿来

Then you should be finally able to see the other branches.然后你应该终于可以看到其他分支了。

I am just updating, when I faced this and how it solved , may be helpful for someone in future.我只是在更新,当我遇到这个问题以及它是如何解决的,将来可能会对某人有所帮助。

I started repo using command $git init and later tried the command $git branch .我使用命令$git init开始回购,后来尝试了命令$git branch But there was no output, later I added a new file and tried to commit.但是没有输出,后来我添加了一个新文件并尝试提交。 that time I got below error那个时候我得到以下错误

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
 

After providing above details command $git branch worked like a charm!!提供上述详细信息后,命令$git branch就像一个魅力!

Had the same issue, but none of the answers helped me.有同样的问题,但没有一个答案对我有帮助。

My problem was when i made the git clone i added the parameter depth .我的问题是当我制作git clone时,我添加了参数depth This was my fault.这是我的错。 So I cloned it again (without the depth parameter) and now i can see all branches.所以我再次克隆了它(没有深度参数),现在我可以看到所有分支。

I was facing similar type of issue.我面临着类似的问题。

So, I first added one file for example index.php in staging area using git add index.php and after that did the git commit -m some-text then I tried git branch and it worked. So, I first added one file for example index.php in staging area using git add index.php and after that did the git commit -m some-text then I tried git branch and it worked.

Hence, You need to make at least one commit before you can see the other branch listed by the git branch command.因此,您需要至少进行一次提交,然后才能看到git branch命令列出的另一个分支。

git branch -M [branch-name]

For instance:例如:
git branch -M master

After this command, probably will should display:在这个命令之后,可能应该会显示:
* master * 掌握

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM