SourceTree for Git: How does Clone, Fetch, Pull and Archive Repository work?
In the basis of this article lies concept of using GIT repository for development: dedicated server stores repository and project team downloads/uploads changes from/to it. SourceTree is an application that helps to work with Git repositories in a visual and user friendly way.
Prerequisites
- You should have SourceTree installed (https://www.sourcetreeapp.com)
- You have access to Bitbucket (https://bitbucket.org/burti)
How to get the project code on your machine
Make sure you are logged in to the Atlassian product suite. You most likely already are, if you are reading this.
Navigate to https://bitbucket.org/burtiChoose a project from the project list.
You will be able to see only the projects you have access to:Choose a Repository.
A project may contain one or several repositories, and a list of all available repositories is displayed:On the top right corner of the screen press the Clone button.
Please note that above the folder/file listing there is a dropdown saying "master", where you can select the branch you would like to clone from.
Go through manual Usage of Git master and develop branches in code deployment to get an overall understanding about the branch concept and how we use it.Please note that Bitbucket will list all the files that are placed in the root folder of the repository. Usually it will contain just a "halcust" folder, but sometimes also "halpatch" and other folders if they are needed for customisations of the system.
- A window with a repository URL and several options and buttons will appear. In the top right corner drop-down select HTTPS instead of SSH.
Click on Clone in Sourcetree. - Your Browser may ask for permission to launch your Sourcetree program - kindly allow it to do so.
A window will appear where you need to choose:
- Checkout branch (see point 4.)
- Destination Path (specify location where local files from repository will be stored)
- Bookmark Name (local name for repository: since there can be several projects you are working on, please choose convenient name for this repository).
Then click Clone button.
Proceed to the destination path you have selected in the previous step.
If running a test environment on the same machine you are cloning this code to - you may either use symbolic links to link needed folders to your development environment or just copy the folders there.
Due to the fact git folders may contain sensitive information about the repository and user credentials we do not recommend however to send copies of these git folders to somebody else. If you wish to do that - please refer to part Creating an archive.
Please note next time when you run SourceTree program you may select repositories with bookmark names defined earlier (please see step 7) i.e. you don't have to repeat points 1 to 7 again.
Basic usage of SourceTree
[-] To switch between branches double-click the required branch. If you don't see it under the BRANCHES section it means you have not checked it out from the server. For this expand the origin under REMOTES, find the needed branch and double-click it to check it out locally.
The branch in bold is the active branch. When switching to another branch it changes the code in all the folders accordingly. I.e. if you are using symbolic links - code of your system is changed at that point already.
[-] To refresh repository status (i.e. see if there are any changes) click on the Fetch button (this will not update files on local machine yet)
[-] Use the Pull button to download the changes from repository to the local branch (selected in the step 7)
Creating an archive
In the case when you need to create an archive of repository for instance to be send to another party, please do the following:
- Open the SourceTree program
- Select needed repository which needs to be archived
- In the top menu select Repository -> Archive...
- Press the "..." button and please select location and the name of the archive.
- You can find the repository's archive under location you have been specified.