Change local branch
When we made a clone based on a single branch (e.g., main) and we need to get the source from another branch, this is impossible. When we need access to all branches for development, use the git clone
command without the --single-branch
option.
When using the deployment script, temporarily remove the --single-branch
option, then run the command as usual. When a development version is needed, use the development deployment script as described in chapter 01.
To switch to another branch:
git checkout <branch name>
Merge a branch into another
When we need to merge our development
into the main
branch, use the following:
git checkout main
git merge <development branch>
Tag a version in the system
Once we finished development and we tested the system, we can tag the version in Git. We use annotated tags so that we can add extra information concerning the release.
To tag the system, we have to make sure that we have the latest version on our local machine. Make sure that we complete all merges and we are aiming at the correct branch. In this example, we tag the main
branch; you use the main branch to release a version.
git tag -a R2.4.2-C2.0 -m "M2.4.2-p1 release with updates from Cloudscraper."
List all tags in the system
In time we will have many tags on the file system. We can find back all the defined tags by:
git tag -l
When searching for specific tags, use a wildcard for the tag:
git tag -l "R.2.4*"
Push tags to the server
To propagate the tag to the remote repo:
git push origin <tag name>
In our example, git push origin R2.4.2-C2.0
pushes the tag to the remote repo.
Check out and trace a remote branch locally
In a virginal development environment created with the myTools/deployDevelopmentSystem.sh
script (see document), there is one local branch (main
) and all remote branches available. To check what is available on the remote repo:
git branch -a
To track a remote branch locally, use:
git checkout -b <local branch> origin/<remote branch>
When you removed the remote information
We you use PHPStorm, it may happen that you accidentally remove the remote information. There is no “Are you sure?” question asked in PHPStorm.
To repair this, do the following:
- To check what is available in the current local Git repository:
git branch
- To add the remote to your local repository (get the URL from Github for the repository it concerns):
git add origin https://github.com/[username]/[repository name].git
- Fetch the information from the remote, then pull:
git fetch git pull
Need detailed information on git commands? You can find the git reference manual here