Adding and removing remote branches

Today I’m going to share another git’s trick to easily set up a remote branch and how to delete them from the remote branch.

Frequently we have to work parallelly to master branch on an exciting feature of your product, right? More often then this is sharing it so your co-workers can contribute and make it even more exciting.

Adding remote branches

The problem is that every time that you create a new branch it’s created locally and you can’t just push your changes because git doesn’t know where to push it. Git stores your branch’s configuration on your .git/config file like this:

[branch "ftw_feature"]
  remote =
  merge =

You can solve this problem manually, every goddamn time setting branch’s remote configurations in .git/config file or if you’re working with git’s version 1.7+ you can use the –set-upstream flag instead.

git branch --set-upstream ftw_feature origin/ftw_feature

Now, just like magic your .git/config file should look like this:

[branch "ftw_feature"]
  remote = origin
  merge = refs/heads/ftw_feature

Or if your you’re sadly running under 1.7 git’s version you can still do a better approach than manually (or not too verbose for me):

git config branch.ftw_feature.remote origin
git config branch.ftw_feature.merge refs/heads/ftw_feature

Removing remote branches

If somehow you screw things up and have to clean the mess before anyone notices, just type:

git push origin :ftw_feature

Or even more intuitive:

git push origin --delete ftw_feature

That does the job.

2 thoughts on “Adding and removing remote branches

  1. Se você já tiver adicionado um repositorio remoto com: git remote add NOME_DO_REMOTE URL_DO_REMOTE e quiser mandar seu branch local para o remote e setar automaticamente o upstream, basta fazer: git push -u NOME_DO_REMOTE NOME_DO_BRANCH

    Like

Leave a comment