In this blog, I am writing about the process of creating a repository in Bitbucket and how to clone that to our local machine. Also, we will see how, from our local machine, we can push the new files that are updated in the repository.
What Is Atlassian Bitbucket
Bitbucket is a web-based version control repository hosting service owned by Atlassian, for source code and
development projects, that uses either Mercurial or Git revision control systems. Bitbucket offers both commercial plans and free accounts.
What is Git Version Control
Git is a distributed version control system for tracking changes in the source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows
How to create a repository
For creating the repository, first, we need to create an Atlassian Bitbucket account.
Using the below link, click the Login button. They have provided an SSO login option. If you want, you can log in through GMail also.
https://bitbucket.org
After login, you will be redirected to the dashboard. Please look at the below snapshot.
The above snapshot is your dashboard page. Please observe the PLUS icon. On the click of the PLUS icon, you can create your repository. After the creation of the repository, it will start to appear under your work section.
Let's create our repository.
Please look into the below snapshot.
The above snapshot is your "Create Repository" page. In that, enter your repository name and check the version control Git.
By following the above workflow, you can create your repository. After hitting the "Create repository" button, the page will redirect to your repository.
As of now, we have created our repository. In the next step, we need to clone our repository on our local machine. For that, first, we need to install the Git on our machine.
Please go through the below link and download the Git executable file.
URL is:- https://git-scm.com/download/win
Please find the below snapshot for reference.
After installing the git version control, we can clone the repository to our local machine.
Cloning Process
Create one folder in your local system. Go inside the folder and right click and select the "Git bash" option. Then, you will get one command prompt.
For cloning, there will be one repository, remote address. Please check the below figure. With that, I marked the copy icon. Just click once your repository URL is copied.
To go inside the local folder, right click and select "git bash" option. In a command prompt run the below command git clone https://
[email protected]/Madansrb/testrepository.git What is GIT? Git clone is a Git command line utility which is used to target an existing repository and create a clone, or copy of the target repository. The structure will be like this git clone <repo> <directory>
The example is below.
Please run the above command in your git bash for cloning the repository. Then you will get one folder. According to our example, the folder name will be a "test repository." Why? Because we created a repository name as a test repository. Please check the below snapshot for the cloning process.
What Next?
Now you are working on that repository or that folder and you have done some work. Let's take an example, you write some text on the text file and save it in that repository. For example, in the "testrepository" folder, I will create one text file and named as info.txt
Our Next Git Command is git status
What is GIT Status
The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. The status output does not show you any information regarding the committed project history.
Please run the git status command on your bash or command prompt, please check the below snapshot
You can observe in the above snapshot, it is saying what all the untracked files in our local repository are.
Next, we need to commit the changes which we made in that repository, and for that we need to follow the below process.
In your git bash or command prompt run the below commands.
- git add info.txt
- git commit -m "your message"
- git push -u origin master
What is GIT Add
Git adds will promote pending changes from the working directory to the staging area.
The Command is:- git add filename. extension
When you want to add more files just mention git add space.
What is GIT Commit?
The "commit" command is used to save your changes to the local repository. Note that you have to explicitly tell Git which changes you want to include in a commit before running the "git commit" command.
The Command is:- git commit -m "your message"
What is GIT Push?
The "push" command is used to publish new local commits to a remote server.
The Command is:- git push
I have run the above statements through git bash -- please check the below snapshot.
By following the above workflow you can commit your changes to the remote repository. Now, please go to your repository in the Bitbucket. Then, you will come to know about the new changes which we made over the repository. Check the below snapshot.
Please click on the info.txt file. It will take you to the file description page. In that, you can see the content of the file. Please check the below snapshot. There, I have marked the Edit button; just click on it.
After clicking on the "Edit" button, you will get the below screen. Please check the below snapshot.
Edit your file and click on the "Commit" button. On the click of the commit button, you will get a small pop up for adding a commit message.
.
Just click on the commit button for saving our new changes.
The important point now is our repository has updated so we need to clone the updated files.
GIT pull
The "pull" command is used to download and integrate remote changes. The target (which branch the data should be integrated into) is always the currently checked out HEAD branch. By default, pull uses a merge operation but it can also be configured to use rebase instead.
In your git bash at the command prompt, please run the below command.
git pull
Please check the below snapshot.
By running the above command, our repository updates with new changes.
Overall, in this blog, we discussed
- How To Create Repository
- How To Instal Git
- How To Clone
- How to Commit
In my next blog, I will discuss how to work with Git Branches.