git branch
List all branches (including remote branches)
git branch -a
List remote branches only
git branch -r
git checkout master
git pull
git checkout branch_name
git pull
git merge master
git push origin branch_name
git remote -v
Example:
origin https://github.com/ipeluffo/some.git (fetch)
origin https://github.com/ipeluffo/some.git (push)
First, you must create your branch locally
git checkout -b your_branch
After that, you can work locally in your branch, when you are ready to share the branch, push it. The next command push the branch to the remote repository origin and tracks it
git push -u origin your_branch
Teammates can reach your branch, by doing:
git fetch
git checkout origin/your_branch
As described below, the -u option sets up an upstream branch:
For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands.
Deleting a remote branch:
git push origin --delete <branch> # Git version 1.7.0 or newer
git push origin :<branch> # Git versions older than 1.7.0
Deleting a local branch:
git branch --delete <branch>
git branch -d <branch> # Shorter version
git branch -D <branch> # Force delete un-merged branches
git remote prune origin
will remove all such stale branches. That's probably what you'd want in most cases, but if you want to just remove that particular remote-tracking branch, you should do:
git branch -d -r origin/coolbranch
From the git remote docs:
prune
Deletes all stale remote-tracking branches under . These stale branches have already been removed from the remote repository referenced by , but are still locally available in "remotes/".
With --dry-run option, report what branches will be pruned, but do not actually prune them.
Don't forget the awesome
git fetch -p
which fetches and prunes all origins.
git reset --soft HEAD@{1}
- Rename your local branch. If you are on the branch you want to rename:
git branch -m new-name
If you are on a different branch:
git branch -m old-name new-name
- Delete the old-name remote branch and push the new-name local branch.
git push origin :old-name new-name
- Reset the upstream branch for the new-name local branch. Switch to the branch and then:
git push origin -u new-name
git filter-branch -f --tree-filter 'rm -rf path/to/file' HEAD
git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -10 | awk '{print$1}')"
git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
git remote add upstream https://github.com/USER/OTHER_REPO.git
source: https://help.github.com/articles/configuring-a-remote-for-a-fork/#platform-mac
-
Open Terminal
-
List the current configured remote repository for your fork.
git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
- Specify a new remote upstream repository that will be synced with the fork.
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
- Verify the new upstream repository you've specified for your fork.
git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
source: https://help.github.com/articles/syncing-a-fork/
From: https://stackoverflow.com/questions/34678950/git-branch-has-diverged-after-rebase-so-why-rebase
The idea is to rebase only if you haven't pushed yet, to replay your local commits. As soon as you have pushed (and are working in a team), you should not rebase the branch on top of master, as it rewrites its SHA1, forcing you to force push the new state of the branch.
Solution from: https://stackoverflow.com/questions/19016698/git-branch-diverged-after-rebase
git push -f origin branch-name
Taken from: https://stackoverflow.com/questions/28572293/can-i-delete-all-the-local-branches-except-the-current-one
Remove all branches except master
:
git branch | grep -v "master" | xargs git branch -D
Remove all branches except current one:
git branch --merged | grep -v '*' | xargs git branch -D