- Pull down branches from a remote:
git fetch
- Viewing all (local and remote) branches:
git branch -a
- Deleting a local branch:
git branch -d <branch name>
- Deleting a remote branch:
git push origin --delete <branch name>
- Pushing a branch to a remote:
git push origin <branch name>
- References:
- Viewing:
git tag
- Tagging a branch:
- Switch to branch:
git checkout <branch name>
- Create a tag of the current state of the branch:
git tag -a <tag name> -m "<commit message>"
- Switch to branch:
- Tagging a commit:
- Find the hash you want to tag
- Create the tag:
git tag -a <tag name> <hash> -m "<commit message>"
- Sharing tags (pushing to another repo, e.g. remote):
- Push a single tag:
git push origin v1.5
- Push all tags from local to remote:
git push origin --tags
- Push a single tag:
- Viewing a tag message:
git show <tag name>
- Note: Bitbucket currently does not display tag messages, but they can be viewed in a CLI
- Showing the commit a tag references:
git rev-list -n 1 <tag name>
- Viewing the commit details:
git show <hash>
- Read more here: Git Basics - Tagging
- Pull latest from the remote:
git fetch
- Switch to the branch to merge into:
git checkout master
- Create a new branch:
git checkout -b merge_master
- Merge:
git merge --no-ff origin release-1.2.0
- Push changes to the remote: 'git push origin merge_master'
- Create a pull request
Rebase is useful when you want to pull shared changes into your local changes. In this case shared changes would be in master and your local changes would be in a feature branch. Rebasing will move your new commits in the feature branch to begin on the tip of master.
Note: Before rebasing, make sure you have changes either checked in to your feature branch or stashed.
- First pull the latest from master:
git checkout master
git pull origin master
- Then switch to your feature branch:
git checkout <feature branch name>
- Now rebase:
git rebase origin/master
Then resolve any merge commits if needed.
See also: Merging vs. Rebasing
Cherry picking allows you to move specific commits from one branch to another. At Reckonsys we use this process to update release branches. Changes should be pushed to master first, then cherry picked into a release branch. We do this to ensure master is always up to date and we do not merge changes from a release branch back into master. Normally a cherry pick should not occur until after the change has been reviewed and merged into master, so ideally you should be picking from the master branch.
- Pull the latest from master so you'll have your merged changed
- Use
git log
to read the commit log - Find your change and the commit hash for your change
Create a feature branch from a release branch. This will be the branch used to pick your change into.
- Fetch the latest:
git fetch
- Checkout the branch:
git checkout <release branch name>
- Make sure you have the latest changes:
git pull origin <release branch name>
- Create a new branch for the pull request. Example:
git checkout -b cherrypick_ticket1350
- Note: Using a naming convention like cherrypick_ makes it clearer to the pull request reviewer that the change has already been merged into master.
- Cherry pick the commit:
git cherry-pick <commit hash from step 1>
- Push the new branch:
git push origin cherrypick_ticket1350
- Create a pull request, setting the destination to the release branch.