The Atlassian Git tutorial provides a streamlined approach to mastering essential Git commands, enabling users to manage their version control efficiently.
Here's a simple code snippet in markdown format:
git clone https://github.com/username/repository.git
Understanding Git Basics
What is Git?
Git is a distributed version control system that allows multiple users to collaborate on a project seamlessly. It tracks changes, enables multiple workflows, and is essential for maintaining a history of project evolution. The key features of Git include:
- Distributed System: Each user has a full copy of the repository, enabling offline work and better data redundancy.
- Branching and Merging: Git’s branching capability allows users to work on different features or fixes independently before merging back into the main project seamlessly.
- History Tracking: It provides a comprehensive log of changes, making it easy to review the project’s evolution over time.
Example: Here is a brief overview of simple Git commands that every user should know:
git init # Initialize a new Git repository
git clone <repository_url> # Clone an existing repository
Setting Up Your Git Environment
Installing Git
Installing Git on various platforms is straightforward. Here’s how you can set it up:
- Windows: Use the Git for Windows installer from the official Git website.
- macOS: Git comes pre-installed with Xcode. Alternatively, you can install it via Homebrew with the command `brew install git`.
- Linux: Use your distribution’s package manager, for example, `sudo apt-get install git` for Ubuntu.
Configuring Git
After installation, configuring Git with your information is crucial:
Setting Up User Information:
To set up your user information, use the following commands:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
To verify your configuration, you can check the settings with:
git config --list

Working with Atlassian Git Tools
Introduction to Bitbucket
Bitbucket is a Git repository management tool from Atlassian that enables developers to store and manage their code. It offers integrations with other Atlassian products like Jira and Confluence, providing a comprehensive toolset for development teams.
Creating a Repository on Bitbucket
Creating a repository in Bitbucket is a straightforward process. Here’s how you can do it:
- Log in to Bitbucket and click on the “Create Repository” button.
- Choose a repository name, set it as public or private, and select a version control system (Git).
- After creation, configure settings such as branch permissions and webhook integrations as needed.
Cloning a Bitbucket Repository
To work with a repository, you will often need to clone it to your local machine. This can be done with the following command:
git clone https://<your_username>@bitbucket.org/<team_or_username>/<repository>.git
This command retrieves the entire repository, including all branches, and prepares it for your local development.
Using Jira with Bitbucket
Integrating Jira and Bitbucket
Integrating Jira with Bitbucket provides a seamless workflow and enhanced visibility into development processes. Benefits of this integration include:
- Automatic Linking: View branch status and pull requests associated with Jira issues.
- Enhanced Reporting: Track development progress directly in Jira.
Setting up the integration involves configuring application links in both Jira and Bitbucket, guiding users through the connection setup process to enable seamless issue tracking and notification handling.

Git Workflow in Atlassian
Understanding Git Workflow
A Git workflow defines how various team members collaborate on a project. Among the most popular workflows are:
- Git Flow: A branching model that emphasizes the use of feature branches, releases, and maintenance branches.
Utilizing a clear Git workflow enhances collaboration, minimizes conflicts, and ensures a structured release process.
Working with Branches
Creating and Switching Branches
Creating a new branch for a feature or bug fix is as easy as:
git checkout -b feature/login
This command creates a new branch named `feature/login` and switches to it immediately, allowing you to work in isolation without affecting the main branch.
Merging Branches
Once development on a feature is complete, merging is the next step. The merge process varies, with options for a fast-forward merge or creating a new commit. Here’s how to merge:
git checkout main
git merge feature/login
This command merges the `feature/login` branch back into the main branch, bringing all changes made in the feature branch.
Pull Requests in Bitbucket
Creating a Pull Request
Pull requests are crucial in the code review process. They allow team members to view proposed changes, give feedback, and approve modifications before merging them into the main branch. To create a pull request:
- Navigate to your repository in Bitbucket.
- Click on “Create Pull Request.”
- Select the branch you want to merge and fill in details like titles and descriptions.
- Add reviewers and link any relevant Jira issues.
Reviewing and Merging Pull Requests
The pull request review process is fundamental for maintaining code quality. Reviewers check the changes, offer feedback, and discuss potential improvements. After the review process is complete, changes are often merged into the main branch, ensuring quality control.

Advanced Git Features
Cherry Picking in Git
Cherry-picking allows you to apply individual commits from one branch to another. This can be particularly useful when you need specific features or fixes without merging an entire branch.
When using cherry-picking, be mindful of the context to avoid conflicts. Here’s how you perform a cherry-pick:
git cherry-pick <commit_hash>
This command applies the changes from the specified commit to your current branch, merging in only relevant updates.
Working with Tags
Tags are used in Git to mark specific points in history, such as releases. They make it easier to reference significant changes over time. To create a tag, you can use:
git tag -a v1.0 -m "Version 1.0 Release"
git push origin v1.0
This command creates an annotated tag named `v1.0`, providing a clear reference point in your repository’s history.

Troubleshooting Common Issues
Resolving Merge Conflicts
Merge conflicts occur when changes in different branches overlap or contradict each other. Identifying conflicts during a merge involves inspecting affected files, where conflicting changes are clearly marked. To resolve a conflict, open the file, edit the conflicting sections, and then complete the merge by adding and committing the resolved files.
Undoing Changes
Mistakes can happen, and Git provides several mechanisms to undo changes. To reset the last commit locally, you can use:
git reset HEAD~1
This command removes the last commit from the branch, returning the working directory to the state prior to that commit while keeping the changes in the working directory.

Best Practices for Using Git with Atlassian
Maintaining a Clean Repository
A clean repository is vital for collaboration. Regularly merging branches and deleting unused or outdated ones helps keep the repository manageable. Always follow best practices for commit messages by being clear and concise about your changes, which will help other team members understand the project history.
Documentation and Resources
Utilizing Atlassian's extensive documentation and community resources can greatly enhance your Git collaboration experience. Bookmarking links to official documentation and creating a cheat sheet of essential commands will empower your workflow.

Conclusion
This Atlassian Git tutorial has covered essential aspects of using Git effectively in conjunction with Atlassian tools like Bitbucket and Jira. By understanding the foundational aspects and leveraging advanced features, you will be well-equipped to collaborate effectively on software projects. Don't hesitate to explore deeper and practice the commands discussed to enhance your Git proficiency. Consider joining our Git training program for more in-depth learning, and continue refining your skills in best practices and workflows.