I create a new branch in Git:
git branch my_branch
Push it:
git push origin my_branch
Now say someone mad
For what it is worth, if you are trying to track a branch that already exists on the remote (eg. origin/somebranch) but haven't checked it out locally yet, you can do:
$ git checkout --track origin/somebranch
Note: '-t' is the shortened version of '--track' option.
This sets up the same association right off the bat.
You can set up a really good alias that can handle this without the overly verbose syntax.
I have the following alias in ~/.gitconfig
:
po = "!git push -u origin \"$(git rev-parse --abbrev-ref HEAD)\""
After making a commit on a new branch, you can push your new branch by simply typing the command:
git po
I use this Git alias instead of copy/pasting the suggestion from Git every time: https://gist.github.com/ekilah/88a880c84a50b73bd306
Source copied below (add this to your ~/.gitconfig
file):
[alias]
pushup = "!gitbranchname() { git symbolic-ref --short HEAD; }; gitpushupstream() { git push --set-upstream origin `gitbranchname`; }; gitpushupstream"
If the below doesn't work:
git config --global push.default current
You should also update your project's local config, as its possible your project has local git configurations:
git config --local push.default current
You can use:
git config --global branch.autosetupmerge always
which will link the upstream branch each time you create or checkout a new branch.
See https://felipec.wordpress.com/2013/09/01/advanced-git-concepts-the-upstream-tracking-branch/
This also works with branch.autosetuprebase
, if you follow a more rebase focused workflow, but don't use this unless you know what you're doing, as it will default your pull behavior to rebase, which can cause odd results.
This is my most common use for The Fuck.
$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
$ fuck
git push --set-upstream origin master [enter/↑/↓/ctrl+c]
Counting objects: 9, done.
...
Also, it's fun to type swear words in your terminal.