How to delete remote branch git

How to delete remote branch git

Git FAQ

Frequently asked questions around Git and Version Control.

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

How can I delete branches in Git?

Before we look at deleting remote branches, let’s discuss the syntax for deleting a local branch in Git.

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

The Git Cheat Sheet

Deleting local branches in Git

Using the «-d» flag, you tell «git branch» which item you want to delete.

Note that you might also need the «-f» flag if you’re trying to delete a branch that contains unmerged changes. Use this option with care because it makes losing data very easy.

Deleting remote branches in Git

Deleting Branches in Tower

In case you are using the Tower Git client, you can simply right-click any branch item in the sidebar and choose the «Delete…» option to get rid of it. But even better: if you made a mistake, you can simply hit CMD+Z to undo the deletion and restore the branch!

Deleting both a local and a remote branch

Just a side note: please keep in mind that local and remote branches actually have nothing to do with each other. They are completely separate objects in Git.

Even if you’ve established a tracking connection (which you should for most scenarios), this still does not mean that deleting one would delete the other, too!

If you want any branch item to be deleted, you need to delete it explicitly.

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.

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

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.

Remote Branches

Remote branches are references (pointers) to the state of branches in your remote repositories. They’re local branches that you can’t move; they’re moved automatically for you whenever you do any network communication. Remote branches act as bookmarks to remind you where the branches on your remote repositories were the last time you connected to them.

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

If you do some work on your local master branch, and, in the meantime, someone else pushes to git.ourcompany.com and updates its master branch, then your histories move forward differently. Also, as long as you stay out of contact with your origin server, your origin/master pointer doesn’t move.

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

To synchronize your work, you run a git fetch origin command. This command looks up which server “origin” is (in this case, it’s git.ourcompany.com ), fetches any data from it that you don’t yet have, and updates your local database, moving your origin/master pointer to its new, more up-to-date position.

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

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

Now, you can run git fetch teamone to fetch everything the remote teamone server has that you don’t have yet. Because that server has a subset of the data your origin server has right now, Git fetches no data but sets a remote branch called teamone/master to point to the commit that teamone has as its master branch.

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

Pushing

When you want to share a branch with the world, you need to push it up to a remote that you have write access to. Your local branches aren’t automatically synchronized to the remotes you write to – you have to explicitly push the branches you want to share. That way, you can use private branches for work you don’t want to share, and push up only the topic branches you want to collaborate on.

If you have a branch named serverfix that you want to work on with others, you can push it up the same way you pushed your first branch. Run git push (remote) (branch) :

If you’re using an HTTPS URL to push over, the Git server will ask you for your username and password for authentication. By default it will prompt you on the terminal for this information so the server can tell if you’re allowed to push.

For more information on the various credential caching options available, see Credential Storage.

The next time one of your collaborators fetches from the server, they will get a reference to where the server’s version of serverfix is under the remote branch origin/serverfix :

It’s important to note that when you do a fetch that brings down new remote branches, you don’t automatically have local, editable copies of them. In other words, in this case, you don’t have a new serverfix branch – you only have an origin/serverfix pointer that you can’t modify.

This gives you a local branch that you can work on that starts where origin/serverfix is.

Tracking Branches

To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:

So here we can see that our iss53 branch is tracking origin/iss53 and is “ahead” by two, meaning that we have two commits locally that are not pushed to the server. We can also see that our master branch is tracking origin/master and is up to date. Next we can see that our serverfix branch is tracking the server-fix-good branch on our teamone server and is ahead by three and behind by one, meaning that there is one commit on the server we haven’t merged in yet and three commits locally that we haven’t pushed. Finally we can see that our testing branch is not tracking any remote branch.

Pulling

While the git fetch command will fetch down all the changes on the server that you don’t have yet, it will not modify your working directory at all. It will simply get the data for you and let you merge it yourself. However, there is a command called git pull which is essentially a git fetch immediately followed by a git merge in most cases. If you have a tracking branch set up as demonstrated in the last section, either by explicitly setting it or by having it created for you by the clone or checkout commands, git pull will look up what server and branch your current branch is tracking, fetch from that server and then try to merge in that remote branch.

Generally it’s better to simply use the fetch and merge commands explicitly as the magic of git pull can often be confusing.

Deleting Remote Branches

Basically all this does is remove the pointer from the server. The Git server will generally keep the data there for a while until a garbage collection runs, so if it was accidentally deleted, it’s often easy to recover.

How do you delete a remote branch in Git?

Before you get into deleting remote branches in Git, we recommend you familiarize yourself with how to delete local branches.

Deleting a remote branch works a bit differently than deleting a branch locally in Git.

Deleting branches in Git is a destructive action – GitKraken enables you to perform this action safely without sacrificing speed, giving you more confidence in your workflow, whether you prefer a visual Git client or CLI.

How to Delete a Remote Git Branch with the GitKraken CLI

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

Rather than using the Git branch command, you will be using the Git push command to delete the remote branch.

It should look something like this:

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

How to Find a List of Your Remote Git Branches

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

Deleting remote branches without enough visibility into your repo can be dangerous. Reduce the risk of losing work or putting your repo in a bad state and get more control of your remote branches with GitKraken.

How to Delete a Remote Branch with GitKraken Client

Because deleting a remote branch is a destructive action, leaning on the visual benefits offered by GitKraken can be beneficial for beginners and experts alike.

ProTip: if you have a large number of branches on one of your remotes, you can use Cmd + Option + f on Mac, or Ctrl + Alt + f on Windows/Linux to filter for a specific branch from the left panel.

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

To delete a remote branch, you will simply right-click on the target branch from the central commit graph or the left panel and then select Delete from the context menu.

Remember when we said this was a destructive Git action? To be extra cautious, GitKraken will ask that you confirm before proceeding, giving you and your team peace of mind.

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

Want to make working with remote branches in Git easier? Download the GitKraken Git Client, now with GUI and CLI, free today.

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

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

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