Work on local source files

When you want to work on a Bitbucket project, you need to make a local copy of the project onto your machine or local network by cloning the repository. See Clone a repository. The next step is to work on the code, add files, remove files, and do whatever you want to do.

Working on files in Mercurial

You will use the Mercurial commands to work on files in your local repository. See the Mercurial documentation for details. Here are the basics of working in a local repository with Mercurial.

Action Mercurial command
Add new files. hg add
Edit the files.  
Remove the file. hg remove
List the files in the repository. hg status
Commit changes. hg commit -m "My Commit message"

Example – Adding Files to a Mercurial Repository

For our example, let's assume you want to add a number of new files to your repository.

  1. Create your new files in your local project directory, or copy the new files from their current location into your local project directory.
  2. Enter hg add at the command line prompt in your local project directory, to add the files to the repository.
    Example and results:

    D:\Atlassian\bitbucketTesting\bitbucketRepository\sarahmaddox>hg add
    adding bat.gif
    adding feet.jpg
    adding foot.jpg
    adding horror.gif
    adding sint1.jpg
    adding sint2.jpg
    adding techw_story1 - Copy.htm
    adding techw_story1.htm
    adding techw_story2.htm
    adding techw_story3.htm
    adding techw_story6.htm
    
  3. Enter hg commit at the command line, to commit the new files to the local repository.
  4. Mercurial pops up a text editor window, allowing you to enter a message describing the commit.

    • Save the text file and exit from the text editor. Mercurial will commit your changes when you exit.
    • Note:You can use a command line option to specify the commit message, thus avoiding the popup text editor:

      hg commit -m "Initial commit of all files to the repository."
      

Working on files in Git

You will use the Git commands to work on files in your local repository. See the Git documentation for details. Here are the basic commands:

Action Git command
Add new files. git add *.*
Edit the files.  
Remove the file. git rm
List the files in the repository. git status
Commit changes. git commit -m "My Commit message"

Example – Adding Files to a Git Repository

For our example, let's assume you want to add a number of new files to your repository.

  1. Create your new files in your local project directory, or copy the new files from their current location into your local project directory.
  2. Enter git add at the command line prompt in your local project directory, to add the files to the repository, then enter git status to see the changes to be committed.
    Example and results:

    $ git add *.*
    $ git status
    # On branch master
    # 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 at the command line, to commit the new files to the local repository.
  4. Git pops up a text editor window (the VI text editor by default), allowing you to enter a message describing the commit.
  5. Save the text file (press Escape to go to command mode, then enter :wq) and exit from the text editor. Git will commit your changes when you exit.

    $ git commit
    [master 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

Note: You can use a command line option to specify the commit message, thus avoiding the popup text editor:

git commit -m "Initial commit of all files to the repository."

RELATED TOPICS

Clone a repository
Pushing Updates to a Bitbucket Repository
http://mercurial.selenic.com/wiki/GitConcepts — Overview of Git for Mercurial users, including a comparison of Mercurial and Git commands.

Was this helpful?

Thanks for your feedback!

5 Archived comments

  1. User avatar

    Anonymous

    Under working on files in Git section you need to change heading from "Mercurial command" and "hg status" to "git status"

    28 Jan 2013
    1. User avatar

      manthony

      Thanks for the catch. This is fixed.

      28 Jan 2013
  2. User avatar

    Anonymous

    The item in the table still says "hg status."

    12 Feb 2013
  3. User avatar

    Anonymous

    still "hg status"... I lost some minutes trying to figure it out... ><

    13 Feb 2013
    1. User avatar

      manthony

      (sad) I don't know what happened fast day; slow mind perhaps. Thanks for the comments. It is fixed now.

      13 Feb 2013
Powered by Confluence and Scroll Viewport