This is part three of a presentation on git, you can find part two here.


git remote

Let’s publish our git-test repository on github.

Go to github.com. If you don’t have an account there you could make one for free.

Github is one of the most popular services for open source projects as of now, but there exists others as well. Most notably bitbucket.org which also let’s you have private repositorys for free.

You could also host your own server to store remote repositories.


On your github profile, go to the Repositories tab.

Github repository

And click the New button


Create repo

Create a name for your repository, and give it an optional description.

You can also choose if the repository will be public or private (the private option is only available if you have a paid account)

As we already have an exsisting repository on our machine, we will not initialize the repository with a README.

Finally, click Create repository


Repo setyp

You will be taken to a screen with different suggestions.

As we already have an existing repository we will choose the second option: …or push and existing repository from the command line.


Verify that you are standing inside your local repository in your terminal using the pwd command. It should display something like /Users/you/Desktop/git-test

Then copy and paste the lines from the github page (don’t copy from this slide as the remote address will be something different for you)

$ git remote add origin https://github.com/you/git-test.git
$ git push -u origin master

That’s it! You have now pushed your local repository to a remote repository residing on github. Refresh your browser tab to see the content of your repository.

Updating

git push

If we continue working on our local repository and commit new changes to it, we regularly want to update our remote on github. We do that with the push command.

Let’s create a new file

$ echo "Some content" > another-file
$ git add another-file
$ git commit -m "Add another file"

And push it to our remote (i.e. github)

$ git push

Summary of what we know so far

Command Description
git init Initialize a git repository
git add Add files for git to track
git commit Commit files and/or changes to files
git log Display history
git diff View changes
git remote Configure remote repositories
git push Push changes to remote repositories

The content of this post was presented on a c0dereview meetup in December 2017, you can view the slides from the presentation here.

Screenshots from github.com