Create, clone, commit to GitHub repository

Reading time: 5 minutes

Description

In this post I will explain how to create a repository using Sourcetree and upload it to GitHub. As part of this process I will also create a Net Core Web App that would be committed to a remote GitHub repository.

What is required

  • GitHub Account
  • Visual Studio
  • Sourcetree GUI for Git


Let’s start by creating a local repository using Sourcetree

Open Sourcetree and add new tab. On new tab click on Create.

On the next screen we should specify where to create a folder that will hold the repository files. Also an important bit is to tick Create Repository On Account. This way we are creating a connection between your local repository and remote repository that will be created after you confirm details by clicking Create.

If you got to your GitHub account you should see the newly created repository.

You can see that the repository folder together with the Git folder have been created at the location you previously specified.

Next step is to open Visual Studio and create a Net Core Web App.

Make sure you use the app name we used to Create repository since Git is tracking that location.

If you go to the location where you placed your repository. You should see the next picture.

Moreover Git tracked these changes. If you go to Sourcetree this is what you should see.

So let’s click on Stage All, add a commit message and click Commit.

Next step is to push your local changes to remote repository.

And if you got to GitHub again you would see all these changes.

Conclusion

Git is a distributed version control system. In order to become an efficient software engineer/developer you need to understand how it works. This way you can track your changes, always have a copy at a remote location. Which is useful if you need to share this repository with a peer engineer or in case you have lost your local machine copy.

As long as you have initiated the repository you are all set up with version control. Then it’s a case of personal preference. Instead of remembering the location of the repository folder on your machine for creation of the application using Visual Studio. You can simply create an application at one local location and copy over to the folder where you established the repository.

Create, clone, commit to Azure DevOps repository

Reading time: 8 minutes

Description

In this post I will explain how to create a repository on Azure DevOps. Clone this very same repository to your local machine and finally commit changes from your local version of repository to remote repository on Azure DevOps.

What is required

  • Azure Subscription
  • Net Core Web App
  • Repository/Repo on Azure DevOps
  • GUI for Git

Azure offers a free subscription plan for personal use. It’s easy to subscribe and practice for your own development or upskilling for a job.


Let’s start by creating a project that will contain your repository

Once you have created a subscription we can then go to Azure DevOps home to create a project.

Enter the project name that would be used throughout this tutorial. Project is like a root folder that would contain all your applications that are related to this project.

For example you can have a project with name TestProject that contains Net Core web api as a backend and Angular application as a frontend. Then you have another project with name FileProcessing that contains some backend code. These two i.e. TestProject and FileProcessing are two different projects with their own domains. These serve for different purposes. Therefore as a good practice should be placed into separate projects.

Next thing we need to select Repos from the left pane. On the right section of the page it should show you the next view.

In there let’s choose an option to Initialize with a README or gitignore.

And for our benefit let’s add both. This is a good practice and both of these files should be added to every project. README serves as an initial documentation that caughts developers first attention. Gitignore is like a safeguard for committing file types that should be left out from pushing it to a remote copy repository.

After we click Initialize it should redirect us to this repo page. From there we can edit details and perform some useful actions.

One of them which is important for this tutorial is action called Clone. The name speaks for itself. In other words we are taking original remote code and cloning it to our local machine. This way we are creating an exact copy of code at that moment of time. Whatever you do, this code/branch on your local machine would not affect the remote code until the moment you use any of these three main commands: commit/push/merge. There are other useful commands but for them you can perform your personal research and see the effect of them on your code.

Clone repository

Once you are at the main page for your repo click the Clone button.

On the slide out click Copy button.

We need this URL (uniform source locator) in order to clone this repository to our local location on our machine.

For this tutorial I will use Sourcetree as a GUI for Git. In Sourcetree add a new tab or under the File menu option choose Clone / New…

On the new tab choose Clone or if you used the File menu option it shows you the required interface.

Paste in the repository URL into the first field. In the second field select the location where you want this repository code to live. By adding \DummyAzureRepo we are creating a root folder for this repository on the fly. Click

When we click Clone the master branch is cloned to our local machine. As you can see this branch contains only two files that we specified during initialization.

If you edit any of the files from the location where you cloned this repository Git should detect these changes.

Let’s create Net Core App to show how Git detects changes

Create Net Core App

Open up Visual Studio and select ASP .NET Core Web Application with Angular template.

On configuration screen type in the name of our repository and add the location where you cloned it but without the root folder name since it was already created in previous steps when we clone the repo.

This is how the root folder of this repo looks before.

After you click Create on the next screen you can specify a web application template if you need one. For this tutorial let’s choose Angular.

And this is how it should look like after you clicked Create.

Now if you go to Sourcetree you should see these changes.

Click on Stage All, write Commit description and click Commit.

At this point these changes are still only on your local machine. For it to be sent to a remote location you need to use the Push command.

Make sure you ticked the right branch. For your Remote branch you can choose any you like. For this time we will keep it as it is. If you are happy with what you see then click Push.

Once you have clicked Push Git sends these changes to the remote repository.

Conlusion

Being able to use Git is essential for being a successful software developer/engineer. Additionally it helps you to keep track of what has changed in terms of code. Another important point is that you got a copy of your code in the cloud. Centralized location that you or your team member can access from anywhere in the world where you got an internet connection.