Learn how to use Git and Bitbucket with either SourceTree, one of the best Git clients available, or using Git from the command line. Whichever you choose you will learn how set up Git, clone this repository locally. Then learn how to make and commit a change locally and push that change back to Bitbucket.
Choose either SourceTree, Atlassian's Git client, or the command line to learn source control using Bitbucket and Git.
Use SourceTree Atlassian's Git client for Windows and Mac
Use Git from the command line for Windows, Mac, and Linux
Finally, if you want a complete end to end tutorial: See our Bitbucket 101.
Unlike SVN, Git makes no distinction between the working copy and the central repository—they are all full-fledged Git repositories.
Git's ability to communicate with remote repositories is the foundation of every Git-based collaboration workflow. To learn more about Git and Git workflows see, Atlassian's Git site.
Download, install and configure SourceTree. Source tree is Atlassian's Git GUI client and one of the most popular on the market.
This section contains the following tasks:
- Install and configure SourceTree: Download, install, and configure SourceTree.
- Clone repository locally: Learn how to clone the bucket-o-sand to your local system.
- Inspect your repository
- Make a commit and push a change
####Install and configure SourceTree
- Go to SourceTree and click Download SourceTree Free
- Open the downloaded file and click Run
- Accept the default settings by clicking Next at each screen. (Windows only: Follow the instructions for installing .Net Framework if prompted.)
- Select a location to install SourceTree or accept the default.
- Click Finish (Mac) or Install (Windows).
The SourceTree welcome wizard opens. Select I agree to the license agreement and click Continue.
Fantastic! Now you have SourceTree installed! Next you'll complete SourceTree configuration.
Configure SourceTree
- SourceTree will install Git, if you do not already have a version installed.
The welcome wizard will help you add an account.
- Select Bitbucket in the Account A section, and enter the same login information you use for your Bitbucket account in the Username and Password fields B.
- Click No to decline SSH keys for the moment. If you have SSH keys you can add them later.
Finally, you can Clone from SourceTree welcome wizard in the next section.
##Clone repository locally Next we'll get the repository to your local system. The git clone copies an existing Git repository as its own full-fledged Git repository. Cloning also creates a remote connection called origin pointing back to the original repository.
###Clone from SourceTree welcome wizard If your installing SourceTree you can clone your repository during the configuration process.
- Select your repository 1 from the list in the welcome wizard.
- Confirm the destination folder 2, or select a new one.
- Click Ok.
Fantastic!! Now you have a clone of the repository on your local system and are ready to work. Next, you can Inspect your repository
###Clone from Bitbucket Learn how to clone a repository starting from Bitbucket to your local system using SourceTree.
- Open the sidebar navigation by clicking on the >> symbol.
- Click Clone A, then click Clone in SourceTree B.
NOTE For Mac you will be asked to launch an application, click OK to continue.
This will prompt SourceTree to open the clone dialog, as shown in the following example:
- Microsoft Windows A
- Macintosh B
Check the destination path and modify it if you wish to place your repository file in a different directory.
You might want to create a directory specifically for your repositories: /repositories/bucket-o-sand
##Inspect your repository Let's take a look around your repository in both Bitbucket and SourceTree.
####Repository in SourceTree The files and titles in your repository might be a bit different, but the basics are the same.
1 Repository bookmarks: displays a list of all the repositories you have listed. You can double click a bookmarked repository to open it in an active tab.
2 Active repository tab: you can have many repositories open at once, each tab lets you view a different repository. In this example working copy is selected, so in the next pane you can see a list of the files in the working copy of this repository.
3 View selection: in this pane working copy you can choose to view only the files in a particular state (such as: All, Modified, Clean).
4 Working copy and Staged changes: here you can see the files in the active view (based on the selection in 3) and drag changed files from working into staged to create a change set to commit.
5 Currently selected file: you can see the diff view of a selected file in the working copy or staged area.
####Repository in Bitbucket Your repository will have some differences but, again, the basics are the same. The view in the following example has the sidebar expanded press [ to expand the sidebar.
A Actions: all the most common actions are here, create a clone, branch, pull request, etc...
B Navigation: this is where you can get to all the things in Bitbucket (such as: source code, list of commits, list of branches).
C README: The view in the preceding example is on the Overview page where you can configure your own README using markdown or plain text.
D Recent activity: lists the most recent commits, pushes, merges, and pull request activity.
##Make a commit and push a change Now your ready to make a change, add that change to your local repository, and push the change to your remote Bitbucket repository.
####Open a file from SourceTree A simple thing like selecting and opening a file from the source control UI can make things move quicker.
- Select All from view selection menu.
- Select the 'sample.html' file, then right click and select Show in Explorer (Windows). Or click ... then select Show in Finder (Mac)
- Using your favorite editor, edit the
sample.html
file. - Change the heading from My First File to Playing in the Sand.
- Save and close the file.
####Commit the change in SourceTree Now you've made a change locally and are ready to go through the git process of adding that change to the project history locally.
The 'git add' moves changes from the working directory to the staging area. This gives you the opportunity to prepare a set of changes (a snapshot) before committing it to the official history.
The git commit takes the staged snapshot and commits it to the project history. Combined with git add, this defines the basic workflow for all Git users.
- Identify the changed file A in SourceTree by noting the change in color and from a checkmark to an ellipsis, as shown in the following example.
- Click and drag the
sample.html
A that file to the Staged files B area. This action is the same as the 'git add' or 'git stage' command. - Click Commit from the actions menu in SourceTree.
- Add a commit message C, then click Commit.
Great! Now the snapshot of your change has been added to your local project history.
####Push the change to Bitbucket The last thing we'll do is push that change to Bitbucket.
Click Push from the toolbar. You'll notice there is a 1 highlighted in the Push action. This is the number of commits ready to be pushed to the remote repository, Bitbucket in this case.
The push dialog opens. Review the settings and click Ok.
Pushing lets you move a local branch or series of commits to another repository, which serves as a convenient way to publish contributions. This is like svn commit, but it sends a series of commits instead of a single changeset.
Congratulations! You've done all the basics! Feel free to use the tutorial repository to learn more, test, experiment, and expand your knowledge. You can jump into the Bitbucket 101 after the Clone your repository section. Or you can check out Atlassian's Git site and learn more about Git workflows.
All of us at Bitbucket and SourceTree hope your experience is a great one! We are constantly working and building a better Bitbucket and SourceTree.
#Command line
Learn the very basics of cloning, committing, and pushing from the command line. Git is a very effective from the command line and it's commands are reasonably easy to learn.
If you don't already have Git installed on your local system see, Set up Git, then return here.
**This section contains the following tasks:
If you are unfamiliar with the Git, or the Git commands here are a couple very good resources:
- Atlassian Git cheatsheet: Nice crisp PDF of all the basic Git commands.
- Atlassian's Git site
Cloning makes a local copy of the repository for you.
-
Click Clone in Bitbucket A, as shown in the previous figure.
-
Make sure the protocol B is set to HTTPS, as shown in the previous figure.
Bitbucket pre-fills the clone command for you.
-
Copy the command C.
-
Open a terminal, or launch a GitBash terminal, on your local machine.
-
Navigate to the directory where you want your files. Use the cd /path-to-your/directory command to navigate to the location you want your repository.
-
Paste the command C you copied in step 3 at the prompt.
-
Press ENTER on your keyboard. The result should be something like.
Git clones your repository from Bitbucket to your local machine.
If you have trouble cloning from these instructions you can check out the more detailed tutorial.
The git clone command copies an existing Git repository as its own full-fledged Git repository with its own history, manages its own files, and is a completely isolated environment from the original repository. Cloning also creates a remote connection called origin pointing back to the original repository
Learn the Git basics of stage, commit, push when you make a change to the 'sample.html' file.
-
Navigate to the directory (folder) where you cloned your repository.
-
Using your favorite editor, open the
sample.html
file. -
Change the heading from
My First File
toPlaying in the Sand
. -
Save and close the file.
-
Navigate to the repository in your command line 'cd path/to/your-repository'.
-
Stage the file with Git.
git add sample.html
-
Commit the change.
git commit -m "changing sample.html"
-
Push to Bitbucket.
git push
The system prompts you for a username/password.
-
Enter your Bitbucket account name and the password.
-
After the push completes, click Commits, in Bitbucket, to view your change.
The 'git add' moves changes from the working directory to the staging area. This gives you the opportunity to prepare a set of changes (a snapshot) before committing it to the official history.
The git commit takes the staged snapshot and commits it to the project history. Combined with git add, this defines the basic workflow for all Git users.
Pushing lets you move a local branch or series of commits to another repository, which serves as a convenient way to publish contributions. This is like svn commit, but it sends a series of commits instead of a single changeset.
Congratulations! You've done all the basics! Feel free to use the tutorial repository to learn more, test, experiment, and expand your knowledge. You can jump into the Bitbucket 101 after the Clone your repository section. Or you can check out Atlassian's Git site and learn more about Git workflows.
All of us at Bitbucket and SourceTree hope your experience is a great one! We are constantly working and building a better Bitbucket and SourceTree.