Github how to delete branch

Github how to delete branch

Git FAQ

Frequently asked questions around Git and Version Control.

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

How to Delete a Branch on GitHub

The GitHub.com browser interface allows you to delete (and create) remote branches. To do this, you need to navigate to the main page of the repository in your browser and then click the «# branches» link. On the branches overview page, you can then choose a branch to delete:

However, it’s very important to understand that you can only delete remote branches, not any of the branches in your local Git repository!

In order to delete a local branch, you need to use Git on your local computer, either via the Command Line or through a desktop GUI.

Deleting a Branch in Git

Using Git on your local computer allows you to delete both local and remote branches. Let’s start with deleting a local branch. On the command line, you can type the following:

To delete a remote branch, you need to use the «git push» command:

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

The Git Cheat Sheet

In case you are using the Tower Git client, you can delete both local and remote branches simply from the contextual menu. Also, if you decide deleting a branch was a mistake, you can undo this with a simple «CMD+Z» keyboard shortcut:

Learn More

Get our popular Git Cheat Sheet for free!

You’ll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That’s why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.

Deleting and restoring branches in a pull request

In this article

If you have write access in a repository, you can delete branches that are associated with closed or merged pull requests. You cannot delete branches that are associated with open pull requests.

Deleting a branch used for a pull request

You can delete a branch that is associated with a pull request if the pull request has been merged or closed and there are no other open pull requests referencing the branch. For information on closing branches that are not associated with pull requests, see «Creating and deleting branches within your repository.»

On GitHub.com, navigate to the main page of the repository.

Under your repository name, click

Pull requests.

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

Click Closed to see a list of closed pull requests. Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

In the list of pull requests, click the pull request that’s associated with the branch that you want to delete.

This button isn’t displayed if there’s currently an open pull request for this branch.

Restoring a deleted branch

You can restore the head branch of a closed pull request.

On GitHub.com, navigate to the main page of the repository.

Under your repository name, click

Pull requests.

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

Click Closed to see a list of closed pull requests. Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

In the list of pull requests, click the pull request that’s associated with the branch that you want to restore.

Near the bottom of the pull request, click Restore branch. Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

Help us make these docs great!

All GitHub docs are open source. See something that’s wrong or unclear? Submit a pull request.

Managing branches

In this article

You can create a branch off of a repository’s default branch so you can safely experiment with changes.

About managing branches

You can use branches to safely experiment with changes to your project. Branches isolate your development work from other branches in the repository. For example, you could use a branch to develop a new feature or fix a bug.

You always create a branch from an existing branch. Typically, you might create a branch from the default branch of your repository. You can then work on this new branch in isolation from changes that other people are making to the repository.

You can also create a branch starting from a previous commit in a branch’s history. This can be helpful if you need to return to an earlier view of the repository to investigate a bug, or to create a hot fix on top of your latest release.

Once you’re satisfied with your work, you can create a pull request to merge your changes in the current branch into another branch. For more information, see «Creating an issue or pull request» and «About pull requests.»

You can always create a branch in GitHub Desktop if you have read access to a repository, but you can only push the branch to GitHub if you have write access to the repository.

Repository administrators can enable protections on a branch. If you’re working on a branch that’s protected, you won’t be able to delete or force push to the branch. Repository administrators can enable other protected branch settings to enforce specific workflows before a branch can be merged. For more information, see «About protected branches.»

Creating a branch

Tip: The first new branch you create will be based on the default branch. If you have more than one branch, you can choose to base the new branch on the currently checked out branch or the default branch.

Creating a branch from a previous commit

Publishing a branch

If you create a branch on GitHub, you’ll need to publish the branch to make it available for collaboration on GitHub.

Switching between branches

You can view and make commits to any of your repository’s branches. If you have uncommitted, saved changes, you’ll need to decide what to do with your changes before you can switch branches. You can commit your changes on the current branch, stash your changes to temporarily save them on the current branch, or bring the changes to your new branch. If you want to commit your changes before switching branches, see «Committing and reviewing changes to your project.»

Tip: You can set a default behavior for switching branches in the Advanced settings. For more information, see «Configuring basic settings.»

Deleting a branch

You can’t delete a branch if it’s currently associated with an open pull request. You cannot undo deleting a branch.

Creating and deleting branches within your repository

In this article

You can create or delete branches directly on GitHub.

Creating a branch

You can create a branch in different ways on GitHub.

Note: You can only create a branch in a repository to which you have push access.

Creating a branch via the branches overview

Creating a branch using the branch dropdown

Creating a branch for an issue

You can create a branch to work on an issue directly from the issue page and get started right away. For more information, see «Creating a branch to work on an issue».

Deleting a branch

You can have head branches automatically deleted after pull requests are merged in your repository. For more information, see «Managing the automatic deletion of branches.»

Note: If the branch you want to delete is the repository’s default branch, you must choose a new default branch before deleting the branch. For more information, see «Changing the default branch.»

If the branch you want to delete is associated with an open pull request, you must merge or close the pull request before deleting the branch. For more information, see «Merging a pull request» or «Closing a pull request.»

On GitHub.com, navigate to the main page of the repository.

Above the list of files, click

Branches. Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

Scroll to the branch that you want to delete, then click

. Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

If you try to delete a branch that is associated with at least one open pull request, you must confirm that you intend to close the pull request(s).

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

If you delete a head branch after its pull request has been merged, GitHub checks for any open pull requests in the same repository that specify the deleted branch as their base branch. GitHub automatically updates any such pull requests, changing their base branch to the merged pull request’s base branch. For more information, see «About branches.»

How to Delete GitHub Branch?

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branch

Destroying something when it’s not necessary is a mandatory thing.

It creates more space for new things and allows us to maintain the rest of the things easily. So, today we are going to explore different ways to delete a branch in GitHub.

Branches are like God’s gift for the developers. If you are a developer, you know what I mean. You may skip the next section and hop to delete the branch section if you are familiar with the branches’ actual use case. And keep on reading if you are a beginner to git or curious about branches.

What are branches?

A branch is a pointer referring to a commit. Reading won’t be good enough to understand about branches. We need to see how the branches work to understand them clearly.

We are going to see how the actual developers use branches in their projects with some illustrations. Note, each circle in the illustrations represents a commit.

Let’s see the workflow of branches with a simple real-time scenario.

So, you are managing things very carefully with the help of branches. There is no mess in it. If there are no things like branches, then imagine the situation that we will get into.

Hence, the conclusion is clear about branches. They are a boon for the developers like us.

Without further ado, let’s see how to delete a branch.

Delete Branch Using Git Client

When we are talking about deleting a branch, we are deleting it locally and remotely. So, don’t confuse yourself when we delete the same branch two times. Let’s see the steps to delete the branch.

Now, recheck the branches. You didn’t find the deleted branch in both local and remote if you have followed the above steps correctly.

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branchBranch List

We will get an error message saying branch not found if we try to delete a branch that doesn’t exist.

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branchDelete Error

That’s it; we have successfully deleted a branch both locally and remotely.

There’s a slightly different way to do it using the GitHub web app.

Delete Branch Using Web

There’s no much difference between the previous method and this one. Here, we are going to use the GitHub web app to delete the remote branch. And we will delete the local branch as we delete in the above method.

Let’s see how to delete the remote branch using the GitHub web app.

Now, we have deleted the branch in the remote. Go to the local repository and delete the branch using the command we have seen in the first method.

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branchBranch List

We still see the deleted remote branch in the list. What’s it? How do we resolve it? See the below scenario where you will get into this type of situation at work.

Let’s assume you are working in a team. Your team lead deleted a remote branch when a particular task is done. How do you know about it? Is there any way to know about remotely deleted branches?

We need to sync the local and remote repositories about the deleted branches. There are certain commands to do it. They are

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branchremote prune Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branchfetch prune

Github how to delete branch. Смотреть фото Github how to delete branch. Смотреть картинку Github how to delete branch. Картинка про Github how to delete branch. Фото Github how to delete branchBranches List

You will see that the remote branch is not showing up in the list. But, the local branch is still present. Yeah, it is. There is not a problem with it. You may keep or delete it.

So, check the branches that are not present in the remote that are present in local. Delete the local branches that are deleted in the remote.

Your branches are clean now. And you are good to go.

Conclusion

Most of the time, we will use the terminal or cmd for any git operations. And it’s convenient. But it’s not mandatory. By the end of the day, it’s a personal preference.

Whatever tool or method you use, the result is the same. Choose the one that you are convenient with and follow it to complete the task—two steps to delete a branch. Delete locally and remotely.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *