How to Create a Repository in Bitbucket Using Git Bash

In today’s collaborative development environment, version control systems like Git are essential. Bitbucket, a Git-based platform by Atlassian, offers powerful tools for managing code repositories, especially for teams.

While Bitbucket provides a user-friendly web interface, many developers prefer the command-line interface for speed and efficiency. In this blog, we’ll walk you through the step-by-step process of creating a Bitbucket repository and linking it using Git Bash.

Prerequisites

Before you begin, make sure you have the following:

  • A Bitbucket account (sign up at bitbucket.org if you don’t have one)
  • Git installed on your local machine (Download Git)
  • Git Bash (comes with Git for Windows)

Step 1: Create a Repository on Bitbucket

  1. Log in to your Bitbucket account.
  2. Click the + icon in the global sidebar and select Repository.
  3. Fill in the required fields:
    • Repository name: Choose a meaningful name.
    • Access level: Decide whether you want the repository to be private or public.
    • Project: Choose or create a project to group related repositories.
    • (Optional) Initialize the repository with a README.
  4. Click Create repository.

Once the repository is created, Bitbucket will display the setup instructions. Keep this page open.


Step 2: Open Git Bash and Set Up Local Directory

Launch Git Bash and navigate to the directory where you want your local repository:

cd /path/to/your/project

If you’re starting from scratch, create a new directory and move into it:

mkdir my-bitbucket-repo
cd my-bitbucket-repo

Step 3: Initialize Git Repository Locally

Run the following command to initialize Git in the local directory:

git init

This command creates a new .git directory that tracks all your changes.


Step 4: Add Files and Commit Changes

Add some files or create a new file like a README:

echo "# My Bitbucket Repo" > README.md

Then stage and commit the file:

git add .
git commit -m "Initial commit"

Step 5: Connect to Bitbucket Repository

Now, go back to Bitbucket and copy the repository URL (either HTTPS or SSH). Then, use Git Bash to link your local repository to Bitbucket:

For HTTPS:

git remote add origin https://yo***********@bi*******.org/your-username/repo-name.git

For SSH:

git remote add origin gi*@bi*******.org:your-username/repo-name.git

Step 6: Push Your Code to Bitbucket

Finally, push your local commits to Bitbucket:

git push -u origin master

💡 Note: If you’re using a newer version of Git where the default branch is main, replace master with main.

You might be prompted to enter your Bitbucket credentials (or an app password if using HTTPS).


Conclusion

Using Git Bash to create and manage Bitbucket repositories allows you to streamline your workflow and integrate version control into your development habits. Whether you’re collaborating with a team or managing solo projects, mastering the command line is a valuable skill.

By following these steps, you’ve now set up a complete Git-to-Bitbucket pipeline right from your terminal. Keep exploring Git commands and Bitbucket features to enhance your development productivity.

Sharing Is Caring:

Leave a Comment