Add, edit, and commit to source files

When you work on a Bitbucket Cloud repository, you'll need to know how to add new files and edit existing files. From there, you'll commit your changes to the repository, making it possible for you (or anyone else) to refer to that point in the repository.

You can make and commit your changes locally before pushing them to Bitbucket, or you can edit from the online editor.

Edit local source files

If you don't have a local copy of the repository on your machine or local network, see Clone a repository first to get a clone of the code.

Add and commit with Git

For a quick reference, here's a few git commands you'll use to work on files in your local repository.

Action

Git command

Add all new files.

git add --all

Remove a file.

git rm <filename>

Commit changes.

git commit -m '<commit_message>'

Get an idea of the git command to use next.

git status

See the Git documentation for more information.

To add and commit files to a Git repository

  1. Create your new files or edit existing files in your local project directory.

  2. Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

    For example:

    1 2 3 4 5 6 7 8 9 10 11 12 $ git add --all $ git status # On branch main # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: 1.png # new file: 2.png # new file: 3.png # new file: 4.png # new file: 5.png # modified: file.txt
  3. Enter  git commit -m '<commit_message>'  at the command line to commit new files/changes to the local repository. For the <commit_message>, you can enter anything that describes the changes you are committing.

    For example:

    1 2 3 4 5 6 7 8 $ git commit -m 'Initial commit of all files to the repository' [main 2f41d64] adding images 6 files changed, 1 insertions(+), 1 deletions(-) create mode 100644 African Daisy.png create mode 100644 Dandelion.png create mode 100644 Ixia.png create mode 100644 Spiked.png create mode 100644 Sunflower.png

Edit files online

If you have write access to a repository, you can edit and commit changes to the repository from the Source files. If you have read access and attempt to edit online, Bitbucket forks the repository, commits your change to the fork, and opens a pull request back to the original repository.

Here's what a file looks like in edit mode:

  • A. File heading – Displays the repository owner (workspace), the project where it lives, and the repository's name.

  • B. File options – Click Diff for the file's diff or History for its commit history to move away from the edit view. If you've already made changes, you'll get a message that asks if you want to cancel your changes to continue.

  • C. Edit options:

    • Syntax mode – Pick the appropriate file type for your file.

    • Indent mode – Choose from Tabs or Spaces. Bitbucket attempts to guess what you're using, but you may have to adjust.

    • Indent size – Update the number of spaces for an indentation. You'll only see this option when Spaces is the Indent mode.

    • Line wrap – Update if you want the lines in your file will wrap.

  • D. Preview / Commit:

    • View diff – Shows you the differences between your changes and the most recent version of that file on Bitbucket. After viewing the diff, click Edit file to go back to the edit view.

    • Commit – Displays the Commit changes dialog where you can enter a commit message and save by clicking Commit.
      If you have repository write access, you can commit directly to the repository or choose to Create a pull request for this change.
      If you don't have write access, Bitbucket automatically creates a fork and pull request that points to the original repository.

Edit a file or diff

From the repository

  1. Select Source in the left navigation.

  2. Click the file you want to open.
    You can search for a specific file b y entering the name in the Filter files field.

  3. Click the Edit button to open the edit view.

  4. Make your changes and any other updates you like to the file.

  5. Click Commit.

  6. Update the commit message if you'd like and press Commit again.

From a pull request

  1. In the repository, select Pull requests in the left navigation bar or the Pull requests tab in the top navigation.

  2. Select the pull request you want to edit.

  3. Select the Files changed tab to display all the files that have been changed. You can also select the Commits tab to display and open specific commits, or you can select commits listed in your Activity in the Overview tab.

Approve a commit

Approving commits may be part of your team’s workflow. To approve a commit, select the Approve button in the upper-right corner of the commit.

Still need help?

The Atlassian Community is here for you.