Creating a Repository on GitHub

Creating a Repository on GitHub

In this post we learn how to create a repository on GitHub, clone the repository, get the status, add files, commit code, push code, and pull down other code changes from the repository.

Step 1: Setup a GitHub account and create a Repository

Once you are logged into GitHub. Click on the "New Repository" button. First, give the repository a name. Then select either "Public" or "Private" depending on who should be able to see this repository. Check the "Initialize with README" checkbox and click "Create Repository". Now, on our repository home page, click on the "Clone or Download" button and copy the link to the repository.

Step 2: Command Line Git commands

1. Open up the command line and use the following command to clone the repository that was just created in step 1. The git clone command will clone everything in the repository on GitHub.com into the servers folder you run this command inside.

git clone git@github.com:jstolpe/github_tutorials.git

2. Add an index.php file inside of the repository we just cloned. Run git status to get the status of the repository on the localbox compared to the repository on GitHub. After running this command, the index.php should show up in red and the command line should state that index.php is an underacted file.

git status

3. Add the file so it is ready to be committed with the git add command. This file basically marks the file as ready for commit.

git add --all

4. Our index.php file is ready to commit at this point with the git commit command. We will be adding a commit message along with this command so when we view the commit log, we can see our comment letting us know the purpose of this commit.

git commit -m "adding index.php to the repository"

5. Before the file actually goes up to the GitHub repository we have one command left to run, git push. This will sent our file up to the repository along with our commit message.

git push

6. Lastly, if others developers have been making changes to the same repository, we want to grab those changes and make sure we have them on our local box. This way we are up to date with the latest and greatest. To do this we run the git pull command. If we already have everything, we should see an "Already up to date" message in the command line. Otherwise, we will see all the new files and updates displayed in the command line after running git pull.

git pull

That is going to do it for the very basics of creating a repository. A few tips I have would be to run git status, alot. This way you can quickly check to see if anything locally differs from the repository. Also, run git pull before you begin working. This will make sure you have the latest and greatest code in the repository before starting in on a new feature. If you do not do a git pull before starting a new feature, and there have been many other developers who have committed lots of updates, you are not starting with the most recent, up to date repository. In this case, you run the risk of many merge conflicts when you are ready to commit your code.

Links

YouTube Video

Code on GitHub

That is going to do it for this post! Leave any comments/questions/concerns below and thanks for stopping by!

To view or add a comment, sign in

More articles by Justin Stolpe

  • Access Tokens with the Instagram Graph API PHP SDK

    To get an access token with the Instagram Graph API PHP SDK, users must first login through the Facebook login dialog…

    5 Comments
  • Instagram Basic Display API: Obtaining an Access Token

    In this post we learn how to obtain and access token from the Instagram Basic Display API with a code passed to us from…

  • Instagram Basic Display API: Creating a Facebook App

    In this post we learn how to setup a Facebook App for use with the Instagram Basic Display API. We create a Facebook…

  • Loading Overlay with HTML, CSS, and jQuery

    In this post we create a global loading overlay using HTML, CSS, and jQuery. There is one line of code to take over the…

  • Putting a Website Online

    In this post we will be putting our website online for the world to see! In order to get our website online we need a…

  • Full Screen Video Background with HTML and CSS

    In this post we learn how to create a full screen video background using HTML and CSS. The video background is always…

  • Fixed Navigation Bar with HTML and CSS

    In this post we learn how to create a fixed navigation bar using HTML and CSS for our website. The fixed navigation bar…

  • Twitter API Login with PHP

    In this video we learn how to create a Twitter app, get the Twitter apps credentials, and use those credentials to log…

    1 Comment
  • Twitter API with PHP! How to Tweet!

    In this post we learn how to use the Twitter API for posting and retrieving tweets from twitter. We also learn how to…

  • Instagram API and Obtaining an Access Token

    In this video we learn how to connect to the Instagram API. We get an access token, connect to the user/self endpoint…

Explore content categories