You are on page 1of 8

A short tutorial to use Bitbucket with SourceTree or TortoiseHg for software development control

The following sections are for SourceTree


1. Please add details how to link, sync, download, pull a project and setup a
repository using SourceTree with Eclipse!!
https://githowto.com/setup
2. How to Pull the latest revision from remote Repo to your local Repo?
Select the master branch from the left panel, and select the “Uncommitted Changes”
from the Graph-Description panel.
3. Click the “Pull” icon, then click OK.
4. In Eclipse, under “Package Explorer” panel, Ctrl+A to select all Package, and press F5
button to refresh.
5. How to Commit to your local Repo and then Push to remote Repo after you
changed the file?
Make sure you save the file you changed.
6. In SourceTree, select the “​Uncommitted Changes​” from the Graph-Description panel.
7. In the bottom left panel, select the file you changed, then click “​Stage All​”, and click “​File
Status​”, then type comment.
8. After typing comment, click “Commit”. This commits to your local repo.
9. (Skip this step if there is no additional/new pull needed to be pulled from the remote
repo.)Click “Pull”, then OK. This pulls the remote repo and automatically merges to your
local repo if there is no merge conflict.
10. (Skip this step if there is no additional/new pull needed to be pulled from the remote
repo.)In Eclipse, under “Package Explorer” panel, Ctrl+A to select all Package, and
press F5 button to refresh.
11. Click “Push” in SourceTree, then OK. This makes sure to push your latest local repo to
the remote one, so other people could pull or merge.
12. How to pull from remote repo and merge locally and then commit and push to
remote repo?
Select the “Uncommitted Changes” from the Graph-Description panel. In the bottom left
panel, select the file you changed, then click “​Stage All​”, and click “​File Status​”, then
type comment.Commit and stage All(this record the change you made in your code to
the stage file as history), then type comment, then commit.
Click Pull to pull the latest repo to local, click OK, then Close.
13. If there is a merge conflict window pops up, click Cancel.
14. Then, click on the file in the bottom left panel to check the conflict lines in the bottom
right.
Discard Hunk if you want to ignore/discard from the local(i.e. Your change).
Stage Hunk if you want to include that piece of change into the history. Stage is just a
status or intermediate file that record the lines/code/hunk change history. So, when you
stage hunk, it doesn’t really merge nor pull.
15. Then, click “Commit” to the local repo after pulling and checking all the conflicts. Type
comment and click Commit. It will automatically merge if no conflict.
16. Then, click Pull, OK. In Eclipse select all project and press F5.
17. In SourceTree, click Push.
18. If you made change in your code and saved, but you want to reverse/return back
to the previous committed version.
Go to source and click on the “Uncommitted Changes”,​ ​and click on the changed file in
the “Unstaged files” panel. This panel indicates that you made and saved the change in
your code, but has not yet be recorded(staged) into your local repo history(i.e. Stage
file).
19. Then, on the right side, just click the “Discard hunk”, and OK, then the changes you
made in your code will not be recorded(i.e. staged) in the repo.
20. In the Eclipse, remember to select all packages in the Package Explorer and hit F5 to
refresh.

Git Checkout command


Sometimes while you are working on a master stem, you encounter some unknown
issues or bugs that you need to dig into the codes and figure out, you may want to review the
code in an earlier/previous revision/build before you modified so that you can debug, compare
and make change from that earlier node/revision.
This can be done by using ​checkout​ command to create a new branch in your local repo.
When you checkout a node/revision from the remote repo, the git creates a local bifurcation,
called branch, in your local repo. So, you can start developing/debugging/changing on the
branch locally, and no one else can see it, until you commit and push this branch to the remote
repo.
1. Right-Click on the node which you want to check out i.e. to create a local branch, usually
this is a previous meta-stable version.
2. Select the Checkout.
The following sections are for TortoiseHg
1. Assuming your partner or you already created a Bitbucket repository, Log in to your
Bitbucket account and click “Repositories”. E.g. in this tutorial the Bitbucket repository resides at
https://bitbucket.org/nanocellect/darklingfpga
2. Go to ​http://tortoisehg.bitbucket.org/​ and download TortoiseHg and install it.
3. Launch the TortoiseHg​ and click File-> Clone Repository…
Use web browser to visit your repository and copy the HTTPS address on the top right
corner:

Then, paste the address to the “Source:” of the Clone dialogue box of TortoiseHg.
In the “Destination:”, you can create a local folder of your name, this is where you want
to use it as your local repository(client) for revision, editing, modifying, etc to the file.
Then, click “Clone”, it should start downloading the files from bitbucket.
4. You may see something like the following:
5. Let’s assume that you have made some change to some of the files or even created a
new folder under your local repository. Now, you have to “​commit​” these changes to your local
repository, where you cloned the folder from the Bitbucket, first. This can be done by right click
the local repository folder -> Hg Workbench, then click the “​Commit​” icon, and check all the
documents and then click on the ​Commit Button​ in the bottom panel, this tells the TortoiseHg
that you made some changes and will create a history/log of the change you made. You may be
asked to input some comment about what and why you made the change. After input the
comment, click the “Commit” to finalize the commit action.

6. If you want to see the log of change, select on a node of the Graph column and then
click the “Revisions Details” icon. The comments and the changes will be shown in one of the
panels.
7. If you happen to like to go to the earlier revision/version of the project, click one of the
revision node and then right click and select the ​Update​, then your local repository is updated to
the revision you selected.
8. After “​Commit​”, which means create a log/tracking of your local repository, you can then
“​Push​” to the remote/server repository on Bitbucket. This can be done by click the “​Push
outgoing changes to (...server address...)​”. This may require you to input your password to
the bitbucket. Once you entered the password, the change you made to the local repository will
be uploaded to the bitbucket.

Pull from Online Repository to Local Repository


Let’s suppose​ your colleague or partners who work on the same project viewed your code
and made some change​ then also “Pushed” to the bitbucket repository. Now, you want to
download, called “​Pull​”, to your local repository.
1. In the TortoiseHg Workbench toolbar, click on the “​Check for the incoming changes
from (...remote repository address...)​”, so that you can see whether somebody has made
change to the file and uploaded(Pushed) to the remote repository. If you see the record/log that
does show someone pushed the remote repository, and if you decided to download(overwrite)
the change to your local repository, you can then click “​Pull incoming changes from (...remote
repository address...)”​ icon; you may be asked to enter your password, then the files from the
remote repository(bitbucket in this case) will start downloading.
2. After it’s done, select the new node in the Graph column and click the Revision Detail
icon to read the comments about what change has your partner/colleague made. If you agree
and accept the change, click the “​Update​” icon and select Update to “​tip​” to overwrite your local
repository, then you can view/run/edit the projects. You should see your revision number is
updated to the latest one you just pulled from remote repository.

Create a repository on Bitbucket

If you are the person who would like to initiate/create a new repository:

1. Go to the Bitbucket website: ​https://bitbucket.org/nanocellect/​, then click ​Create->Create


Repository. ​Select the Owner,​ ​Fill in the Repository name, Description, ​Uncheck the “This is
a private repository”, Select the Mercurial for Repository type, and select a Language,
e.g. VHDL. ​Then, click “Create repository”.
2. You will be led to a new page:

Please click the ​“Clone”​ and copy the string in HTTPS:


E.g. hg clone ​https://chiennanocellect@bitbucket.org/nanocellect/chienbitbucketturorial

3. In your computer, you may already have some folder which you want to share/push to
the online repository. Here is how you start. Launch TortoiseHg Workbench and click File->New
Repository, then in the ​Destination path​, Browse to the folder which you want to create a local
repository for version control. Then, click Create.
4. Then, check the check box to select the files you want to regulate the version (i.e. to
commit to the local repository). And type some comments. Then, click ​Commit ​and ​Add​.

You should see on the top panel, the Rev number change from -1 to 0.
5. To ​PUSH​(i.e. upload) your ​committed local repository​ to the online bitbucket, select
the 0+, and click the ​Push ​icon. It should pop up a warning message saying that the remote
repository URL or path has not been configured…. Click OK.
6. You should now see a horizontal text bar box with a ​disk icon​ in front of it. Please paste
the HTTPS link you copied in Step 2 to the text box(​Without hg clone​). Then, click the “​Push
outgoing changes to selected URL​”, then Yes. You might be prompted to enter you
password, then OK. After a moment, depending how large your folder is, you can refresh the
webpage of the Bitbucket, then you should see the files and repository has been pushed there.
7. Let’s say if you made some change to the files, and you want to commit to the local
repository and push to the online bitbucket repository. In the TortoiseHg workbench, select the
top tip in the graph, whose description should show “​Working Directory​”. Then, click the
“​Refresh the list​” icon, and check the files changed, then put some comments and click
“​Commit​”
the file changes are committed to your local repository. Then, you can click the “​Push outgoing
changes​” icon to push to the online repository.

You might also like