Storing code using Git in Github or Bit Bucket

June 10, 2018

GitHub and BitBucket are the two most famous places to store your code. Both these provides us public as well as private repositories. Public repositories are free and can be accessed by anyone whereas private are paid and can only be accessed if you know the credentials.

It does not matter in which programming language you are writing your code.

In this session, we are going to learn how to store code in GitHub and BitBucket and then accessing it from anywhere. We will also see how you can push or pull code through command line and via Eclipse IDE.

Storing code in GitHub:

Creating an account on GitHub:

Navigate to the GitHub website. http://www.github.com

Sign up to GitHub using your email Id and then login with those credentials.

Create a new repository by either clicking on Start a project or click on the + button or clicking on New repository link. All three options are highlighted in below image.

Give the name of your repository –> select private or public –> Click create a repository.

The repository is created now. Copy the path of the repository by clicking on copy button. See highlighted button in below image.

Storing code in Bit Bucket:

Creating an account on bit bucket:

Navigate to https://bitbucket.org/

Create a new account by signing up using your email Id on https://bitbucket.org/account/signup/

Enter a unique name like https://bitbucket.org/qatechhub

Next step is to create a repository by clicking on Create Repository link.

Copy the path of Bit Bucket link by clicking the copy button.

Pushing code to this GitHub or Bit Bucket repository using Eclipse.

Create a new Java project in eclipse by File –> New –> Other –> Java Project –>click Next.

After creating a Java project –> right click on project name –> Team –> share project.

Click on create and give the path or repository, this will be a local repository on your machine which is similar to workspace in eclipse.

Click finish

You will see a change in the package explorer. A tag <repository name> will be appended to the name of the project.

Pushing the code from local repository to GitHub or Bit Bucket repository:

The first step is to add the code or files to the index which you want to push to the remote repository (GitHub or Bit Bucket).

Right click on project name –> Team –> Add to Index.

Add to Index will put a + symbol to all those files are new as below:

If there is a file which you do not want to push. Right-click file –> Remove from Index.

Next step is to commit and push the code.

Right click project –> Team –> Commit.

This will open up a Git Staging window where you have a window like – Unstaged changes (file changes which you do not want to push), staged changes(file changes which you want to push), commit message(a message or a reason for pushing changes), Author name, Committer name.

You can move files in between staged and unstaged changes windows.

Once you are sure about the files which you want to push click on commit and push button.

Next, it will ask you for Destination Git Repository. Enter URI (path of your Github or Bit Bucket repository), username and password and click next.

Next, it will ask you for the branch. Branching we will discuss in later tutorials for now keep it master branch. Click Next –> click Finish. This will push your code to the respective repository.

 

Now your code is pushed to the repository. Login to GitHub or BitBucket to see the code.

PS: For any questions, queries or feedback. Feel free to write us at saurabh@qatechhub.com or support@qatechhub.com

Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra:

Leave a Comment: