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 the blog!

39 comments

  1. hey tthere and thanhk youu for your innfo –
    I’ve certainly picked uup anytging neww from right here.
    I did however expedrtise sveral technical isssues usig this website,
    aas I ecperienced to reload tthe website lotts of times previous
    to I could gett iit to lad correctly. I hhad been wondering if your web hosxt is OK?
    Noot that I’m complaining, but sloow loading instancess times will sometimes affdect your poacement in glogle
    annd cann damage yor hiogh quality sscore if ads and
    marketinjg wwith Adwords. Well I’m adding tthis RSS to myy e-mail annd can look outt ffor a lott mmore
    of your reswpective intrijguing content. Make ssure youu updwte this agan soon.

  2. This is a good tip especially to those new to the blogosphere. Brief but very precise infoÖ Many thanks for sharing this one. A must read article!

  3. I’ll right away take hold of your rss feed as I can not to find your e-mail subscription link or e-newsletter service. Do you have any? Please permit me understand in order that I may subscribe. Thanks.

  4. Good day! This is my first visit to your blog! We are a group of volunteers and startinga new project in a community in the same niche.Your blog provided us valuable information to work on. Youhave done a extraordinary job!

  5. Heya i’m for the first time here. I came across thisboard and I to find It really useful & it helped meout a lot. I hope to provide one thing again and aid others like you helped me.

  6. Hello! I could have sworn I’ve been to this blog before but after reading through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be book-marking and checking back frequently!

  7. I need to to thank you for this fantastic read!! I definitely enjoyed every little bit of it. I’ve got you book marked to check out new things you postÖ

  8. Hey there! I could have sworn I’ve been to this blog before but after checking through some of the post I realized it’s new to me. Nonetheless, I’m definitely glad I found it and I’ll be bookmarking and checking back often!

Leave a Reply

Your email address will not be published. Required fields are marked *