BitBucket is an external source code repository server that hosts our shared code. Our repositories use Git as the version control program to keep track of file changes. The idea is you make changes to code on your local machine then share your code with everyone else by uploading to BitBucket.
The instructions below guide you step-by-step in uploading files to BitBucket using the commandline. Git is one of the most popular version control programs but it is not easy for beginners. If you want to do something that deviates from these steps, consult a git reference. Once you understand the basics of the git workflow, you can use a GUI program which can combine multiple steps in a single click.
1) Install git on your machine if you don’t already have it. If you are using ubuntu:
sudo apt-get install git-core
2) Navigate to the directory you want to contain your local copy of the repository.
3) Clone the Bitbucket repository. Under your current directory, a new local repository folder is created containing a copy of all the files in the Bitbucket repository. Git will prompt for a Bitbucket username and password.
git clone <bit bucket repository URL>
$ git clone https://bitbucket.org/rieseberglab/sunflowergenome Cloning into 'sunflowergenome'... Username for 'https://bitbucket.org': me Password for 'https://email@example.com': remote: Counting objects: 955, done. remote: Compressing objects: 100% (694/694), done. remote: Total 955 (delta 362), reused 773 (delta 244) Receiving objects: 100% (955/955), 31.79 MiB | 1.04 MiB/s, done. Resolving deltas: 100% (362/362), done.
In the example, we clone the “sunflowergenome” Bitbucket repository. In the current directory, a “sunflowergenome” folder is created, containing the local “sunflowergenome” git repository. You can tell if a folder is a local git repository if it contains “.git” folder. The .git folder contains the index that tracks repository changes.
4) Navigate into your desired local repository folder so that git knows which repository to manage.
5) Modify or add desired files and folders in your local git repository.
6) “Stage” your new and modified files track the changes in the git repository index. If you modify a file after staging, you must restage that file or the changes will not be recorded in the index.
git add <new or modified file>
7) Check the status of your repository files to ensure that your file was staged. You can check the repository status at any time to find state of any repository file (staged, unstaged but modified, conflicting with Bitbucket, etc).
EG) The file test.pl has been successfully staged and is ready to be commited to the index.
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: test.pl #
8) “Commit” your files to make a snapshot of all file changes in the index. You can reset your files to the state in any commit snapshot. Commit snapshots are handy if you make file changes then decide that you liked another version better. You can also isolate buggy code by comparing snapshots where code worked and code didn’t work. These snapshots only exist on your local machine until you share them on BitBucket. Unstaged file changes are not included in the index and are not included in snapshots.
git commit -m < commit message describing your changes>
9) Check that your commit worked by examining the commit logs.
10) Share your file changes with everyone else by uploading them to BitBucket. Before you do that, “Pull” from Bitbucket to merge the latest code into your local repository. It will prompt you for your Bitbucket username and password.
git pull <bitbucket repository URL>
11) If the latest BitBucket snapshot contains modifications to the same files that you locally modified and tracked in your index, git will notify you of merge conflicts. Otherwise, you can skip to step 12. If there are merge conflicts, open a merge tool to integrate file modifications from BitBucket with your own. Depending on your merge tool, your changes may be automatically staged. Commit your changes afterwards.
git mergetool [-t <desired merge tool. Uses default merge tool if you don't specify.]
12) Upload your changes to Bitbucket to share them with everyone else. Git will upload your latest commit snapshot.
git push <Bitbucket repository URL>