Git That Code!

All about remote servers, pushing, pulling, and cloning.

https://unsplash.com/photos/MAYEkmn7G6E

In this post, I’m going to talk about the popular remote servers, GitHub, GitLab, and BitBucket, how to get your code on the server, and retrieve code from it. Let’s get started!

Remote Server Options

There are 3 Git server options that you hear about, well you might actually only hear about the first 2. You could also roll your own, but that’s a bit out of the scope here. So, here are some options that are free and offer quite a bit.

  • GitHub
  • GitLab
  • BitBucket

These are just the most “popular” options and each have their pluses and minuses, but here are some general features that each offer on their free tiers.

  • Free, unlimited private repos (where the code lives)
  • Issue tracking
  • Wiki per repo

Now here is what each is mainly known for:

  • GitHub: Open source software. Most people put their OSS on GitHub for others to contribute to or use
  • GitLab: Contains more devop options like Continuious Integration and more access levels
  • BitBucket: Has unlimited private repos and integrates well with JIRA and other atlassian software

In this post, I’ll be demoing using GitHub, but it is relatively the same on all 3 platforms.

How to get code to the server

Now, that we know where to store code, let’s talk about getting code onto the server. To get code onto the server, you must push the code into a repository.

What I like to do is start the repo in your choice of server, mine is GitHub and then get the repo onto my computer, but in the last post I walked through making a git repo locally, so let’s get that repo onto GitHub.

The first thing I need to do is make a blank repository. This repository is going to be where the code will be stored.

  1. Open your browser of choice
  2. Navigate to your server
  3. Sign in
  4. Create a new repository
  5. Don’t check any of these boxes, but make sure to give your repo a name.

Now, this is the remote repo that needs to be added to our local repo. GitHub gives us some handy quick setup which is what we are going to follow.

  1. Open your terminal app
  2. Navigate to your local repository
  3. Add a remote url to the local git repository git remote add origin
  4. Now we need to create a branch locally git branch -M main
  5. Then, we push it to the server. basically we are uploading it to the server now. git push -u origin main

Now the code should be in my GitHub repo. Let’s refresh and BAM it’s there.

After commits have been made, we need to run git push which will push the commits to the remote server.

When do you push your code? All the time. Sometimes I do it after a long session. Sometimes I do it after each commit. Just make sure your code in the remote server is as up to date as possible. In case things go south, you want a way o bring that work back and the history back.

How to get the code from the server

We just talked about pushing code to the server, now let’s talk about pulling and cloning code from the server. There are two basic commands to get the code from the server. They are git clone and git pull. Each are used in different scenarios.

  • git clone is mainly used to get a repository from the server that doesn't exist on the local computer. If you stumble upon a project on GitHub that you want to hack on, then you clone it to your machine.
  • git pull is mainly used to get changes to a repository that you are working on locally. It can be used if you're working on a team or make a change on the web that you need on your computer.

Let’s walk through an example of cloning a repo. I’ll clone my hello-world-js repo from forever ago.

  1. Open terminal
  2. Navigate where you want to store the repo for me that’ll be my developer folder
  3. Grab the URL to clone from the repo
  4. In the terminal type the command git clone git@github.com:maeganwilson/hello-world-js.git and press enter
  5. DONE!

Now, we can edit the file and push it back.

Alright, cloning was kinda easy, now let’s try pulling. Like I said, pulling can only happen when there are changes on the server that you need to git. So, I’m going to make some changes in GitHub.com in the iHog repo.

Now, in my terminal, I’m going to change my directory to iHog and then run git pull.

In the terminal, we see how many changes were made and a bit more.

That’s a very basic overview of using a remote server and how to pull and clone code.

A non-binary person that develops iOS apps as a part time gig. I share my knowledge in posts and on my twitch streams, https://twitch.tv/maeganwilson_

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store