- Create a branch on a remote (pushing a branch to a remote)
- Delete a remote branch
- Switch from HTTP to git/ssh
- Set upstream branch
- Abbreviated status
- Useful Git aliases
Having created a new feature branch locally, you can push to a remote, creating a new branch destination using.
git push -u origin feature_branch
-u sets upstream tracking and is optional.
Having pushed your feature branch,
git push origin feature_branch
git branch -d feature_branch
then delete remotely,
git push origin --delete feature_branch
which is short hand for
git push origin :feature_branch. The colon looks out of place but its really just the everyday syntax of
git push <remote> <local branch>:<remote branch> with a empty string representing the local branch. Effectively, it’s saying, take no branch from my local branch and push it to the remote branch.
More on remote branches from git ready
If you’re using HTTPS as your fetch url (check your
.git/config file), you’ll likely be asked for your username and password on each push. Switch to git/ssh with the following (assuming you’ve setup ssh).
git remote rm origin git remote add origin email@example.com:tobyweston/playground
This will alter your
.git/config file from
[remote "origin"] url = https://github.com/tobyweston/playground.git fetch = +refs/heads/*:refs/remotes/origin/*
[remote "origin"] url = firstname.lastname@example.org:tobyweston/playground.git fetch = +refs/heads/*:refs/remotes/origin/*
but won’t associate the remote branch with a local one. You’ll need to set an upstream branch for that.
git pull after switching from HTTPS to git/ssh above will give you an error.
You asked to pull from the remote 'origin', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line.
Set the upstream branch with
git branch --set-upstream master origin/master
which should report back,
Branch master set up to track remote branch master from origin.
and change your
.git/config file from
[branch "master"] remote = origin merge = refs/heads/master
Do the same for any other remote branches.
git status output
git status -sb version
Set the proxy, your user name and a couple of useful configurations. Feed straight in from the shell.
Some useful aliases.
- Pragmatic Guide to Git (Pragmatic Programmers), Travis Swicegood
- Pragmatic Version Control Using Git: 1 (Pragmatic Starter Kit), Travis Swicegood
- Pro Git (Expert’s Voice in Software Development), Scott Chacon