Avoid pushing a specific branch to the wrong remote

Asked

Viewed 275 times

2

Hello,

Can anyone instruct me on how to avoid screwing up with git? At next aspect:

I have a project with 2 "remotes" configured (imagine one of the company - company - and other private - service). I maintain a "branch" that sync with company repository (master -> company/master) and other that sync with my version of the project that is slightly different (my -> meuservidor/master).

Now: how do I set up git to stop me from doing stupid things and "push" from my personal "branch" to the company server, by example?

2 answers

2


First,

Configure the push:

git config --global push.default simple

Then use the "track" with your branch:

git branch master --set-upstream-to=empresa/master
git status         # mostra conexão entre master e empresa/master

Afterward,

git checkout master
git push                      # Para empresa
git push meuservidor master   # Para seu servidor privado

You can create and use alias:

git config --local alias.push-empresa "push empresa master"
git config --local alias.push-servidor "push meuservidor master"

git push-empresa
git push-servidor
  • Good idea about aliases.

  • Great idea! Simple and functional.

0

If you use Git with Windows there is a very interesting Powershell extension called Posh-git, you can download it via Chocolatey here. This extension shows the current branch name at the prompt, i.e., you no longer need to type git status to verify which current branch.

  • I use linux, but there is something that does the same in linux as well. It does not serve what I want, although it could help. I think I’ll just trust to always do just "git push" and never explicitly indicate the wrong "branch".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.