Friday, January 5, 2018

Getting started with Git and Bitbucket

Overview


In this example you install Git, create a local Git repository with one text file, create a Bitbucket repository, push the local repository to the remote Bitbucket repository, clone the Bitbucket repository to the local repository, change the file content, commit and push it back to the Bitbucket repository and finally update the original local text file from the remote Bitbucket repository.

Instructions


Go to https://git-scm.com/downloads and install Git to you computer. The settings when installing:

















































 

Create a "C:\GitTest\SomeProject" directory and create a file with some content in it.



In the command prompt go to the C:\GitTest\SomeProject directory and enter a command "git init".



Enter the commands "git add ." that adds files in the directory to the local repository and then commit the changes (adding a file in this case) with the command git commit -m "Initial commit"



Go to https://bitbucket.org and create an account.

When logged into Bitbucker click the + -sign.



Click "Repository"
 
 Enter the name and click "Create repository".
 

Click "I have an existing project".



Here you get the instructions how to initially push files to a repository in you Bitbucket account.





Connect you existing repository to the Bitbucket repository and push the file to the Bitbucker repository.



Now you have the Testfile.txt in the Bibucker repository.



Let's get the remote repository content to some other directory on your computer.

Create a new directory C:\GitTest\CloneOfSomeProject

You get the address of the remote repository from the Overview page.



Use "git clone" command to clone the repository under the "CloneOfSomeProject" directory.



This will create a"someproject" directory / repository with the file from the remote repository.



 Make a change to the "C:\GitTest\CloneOfSomeProject\someproject\Testfile.txt" file.



In the C:\GitTest\CloneOfSomeProject\someproject directory enter the command git commit -am "Edited something"



Enter the command git push origin master

 



In the Bitbucket you can now see that the changes were uploaded.

Now you want to update the original local repository C:\GitTest\SomeProject with the changes in the Bitbucket remote repository. Go to the C:\GitTest\SomeProject directory and enter the command "git pull".




The "C:\GitTest\SomeProject\Testfile.txt" file is now updated with the changes.