http://www.sqlservercentral.com/blogs/steve_jones/2017/05/18/devops-basics-connecting-to-a-git-remote/

Printed 2017/05/26 10:39PM

DevOps Basics – Connecting to a Git Remote

By Steve Jones, 2017/05/18

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers. This is also a part of a basic series on git and how to use it.

As I work more and more with Git, I find myself learning little tips and tricks that are helpful. One of those tricks is adding a remote to my local repo so that I can sync with it, and start collaborating with others. In many cases, I find myself pulling from a remote repo and pushing back, and much of the work is done for me. However, if I create a local repo, how do I get this to a remote service?

Certainly some tools like VS or GitHub for Windows/OSX/etc help, but I like to understand the process myself, so I spent a few minutes practicing.

First, I create a new repo with some documents. This is basic git stuff that you should understand, but if not, I’ve written a few posts on git basics. Here’s the first steps I took in another post.

2017-04-26 14_01_08-cmd

Create a Remote

The next step is to have a remote git repo, which is really a remote git init spot. For this post, I’ll make on at Github, but the process is similar anywhere. In my repositories list, there is a new button.

2017-04-26 14_32_08-Your Repositories

I click that and get a form. In my case, I’ll name this to match the repo on my local machine. Life is easier if you match names, but you don’t have to.

2017-04-26 14_33_51-Create a New Repository

Once I do that, Github guides me along. I get a page with quick setup.

2017-04-26 14_34_24-way0utwest_GitTests

In my case, I want to push things from an existing repo on my machine. Again, tooling may do this for me, but from the command line, I need to add a “git remote”. I’ll use the “add” option, and I specify a name and URL. These are shown near the bottom of the image. I’ll run these locally.

2017-04-26 14_35_38-cmd

Once I do this, my local git repo has a remote repo (called origin) that it can send code to (push) and get code from (pull). Git manages conflicts and versions and all that.

If I try to just push, what I’ll find is I don’t have enough config.

2017-04-26 14_38_55-cmd

My push needs to specify the remote and then the branch. Let’s do that.

2017-04-26 14_39_29-cmd

Once I do this, 7 objects got pushed, which includes some of the .git stuff. If I go to Github and look at the repo, I see this under Code.

2017-04-26 14_40_15-way0utwest_GitTests_ Git testing

I’ve connected my local repo to a remote, and copied my code up. Now I can push/pull as I make changes (or others do) to keep my local copy in sync with the remote.

I’ll look at other flows in a future post.

SQLNewBlogger

This was a fairly quick post, about 10 minutes, as I connected up the local stuff to the remote. I’ve done this before and learned some of this the hard way, but this post allows me to organize my thoughts and be sure I understand what’s going on.

I did end up spending a few minutes looking at the git docs to be sure I was describing things correctly.


Filed under: Blog Tagged: DevOps, Git, SQLNewBlogger, syndicated
Copyright © 2002-2017 Redgate. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.