GitHub For Beginners: Commit, Push And Go
In Part 1 of this two-part GitHub tutorial, we examined the main uses for GitHub and bega5n the process of signing up for a GitHub account and creating our own local repository for code.
See also GitHub For Beginners: Don’t Get Scared, Get Started
Now that these steps have been accomplished, let’s add the first part of your project now by making your first commit to GitHub. When we last left off, we’d created a local repository called MyProject, which, when viewed in the command line, looks like this screenshot.

Local repo as viewed from Terminal.
On your next line, type:
touch Readme.txt
This, again, is not a Git command. It’s another standard navigational command prompt. touch really means “create.” Whatever you write after that is the name of the thing created. If you go to your folder using Finder or the Start menu, you’ll see an empty Readme.txt file is now inside. You could have also made something like “Readme.doc” or “Kiwi.gif,” just for kicks.
You can clearly see your new Readme file. But can Git? Let’s find out. Type:
git status
The command line, usually so passive up to this point, will reply with a few lines of text similar to this:
# On branch master
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# Readme.txt

What’s going on? First of all, you’re on the master branch of your project, which makes sense since we haven’t “branched off” of it. There’s no reason to, since we’re working alone. Secondly, Readme.txt is listed as an “untracked” file, which means Git is ignoring it for now. To make Git notice that the file is there, type:
git add Readme.txt
Notice how the command line gave you a hint there? All right, we’ve added our first file, so it’s time to take a “snapshot” of the project so far, or “commit” it:
git commit -m “Add Readme.txt”

The highlighted text is our first commit.
The -m flag, as noted in the terms directory in Part 1, simply indicates that the following text should be read as a message. Notice the commit message is written in present tense. You should always write your commands in present tense because version control is all about flexibility through time. You’re not writing about what a commit did, because you may always revert to earlier. You’re writing about what a commit does.
Now that we’ve done a little work locally, it’s time to “push” our first commit up to GitHub.
“Wait, we never connected my online repository to my local repository,” you might be thinking. And you’re right. In fact, your local repository and your online one are only connecting for short bursts, when you’re confirming project additions and changes. Let’s move on to making your first real connection now.
Connect Your Local Repository To Your GitHub Repository
Having a local repository as well as a remote (online) repository is the best of both worlds. You can tinker all you like without even being connected to the Internet, and at the same time showcase your finished work on GitHub for all to see.
This setup also makes it easy to have multiple collaborators working on the same project. Each of you can work alone on your own computers, but upload or “push” your changes up to the GitHub repository when they’re ready. So let’s get cracking.2
First, we need to tell Git that a remote repository actually exists somewhere online. We do this by adding it to Git’s knowledge. Just like Git didn’t acknowledge our files until we used the git add command, it won’t acknowledge our remote repo yet, either.
Assume that we have a GitHub repo called “MyProject” located at https://github.com/username/myproject.git. Of course, username should be replaced with whatever your GitHub username actually is, and myproject should be replaced with the actual title you named your first GitHub repository.
git remote add origin https://github.com/username/myproject.git
The first part is familiar; we’ve used git add already with files. We’ve tacked the word origin onto it to indicate a new place from which files will originate. remote is a descriptor of origin, to indicate the origin is not on the computer, but somewhere online.
Git now knows there’s a remote repository and it’s where you want your local repository changes to go. To confirm, type this to check:
git remote -v

This command gives you a list of all the remote origins your local repository knows about. Assuming you’ve been with me so far, there should only be one, the myproject.git one we just added. It’s listed twice, which means it is available to push information to, and to fetch information from.
Now we want to upload, or “push,” our changes up to the GitHub remote repo. That’s easy. Just type:
git push
The command line will chug through several lines on its own, and the final word it spits out will most likely be “everything up-to-date.”

Git’s giving me a bunch of warnings here since I just did the simple command. If I wanted to be more specific, I could have typed git push origin master, to specify that I meant the master branch of my repository. I didn’t do that because I only have one branch right now.
Log into GitHub again. You’ll notice that GitHub is now tracking how many commits you’ve made today. If you’ve just been following this tutorial, that should be exactly one. Click on your repository, and it will have an identical Readme.txt file as we earlier built into your local repository.
All Together Now!
Congratulations, you are officially a Git user! You can create repos and commit changes with the best of them. This is where most beginner tutorials stop.
See also: Github’s Tom Preston-Werner: How We Went Mainstream
However, you may have this nagging feeling that you still don’t feel like an expert. Sure you managed to follow through a few steps, but are you ready to be out on your own? I certainly didn’t.
In order to get more comfortable with Git, let’s walk through a fictional workflow while using a little of everything we’ve already learned. You are now a worker at 123 Web Design, where you’re building a new website for Jimmy’s Ice Cream Shop along with a few of your coworkers.
You were a little nervous when your boss told you that you’d be participating in the Jimmy’s Ice Cream Shop webpage redesign project. After all, you’re not a programmer; you’re a graphic designer. But your boss assured you that anyone can use Git.
You’ve created a new illustrations of an ice cream sundae, and it’s time to add it to the project. You’ve saved them in a folder on your computer that is also called “icecream” to prevent yourself from getting confused.
Open up the Command Line and change directory until you’re inside the icecream folder, where your designs are stored.
cd ~/icecream
Next, initialize Git so you can start using Git commands inside the folder. The folder is now a Git repository.
git init
Wait, this is the right folder, right? Here’s how you check and make sure this is where you stored your design:
git status
And this is what Git will tell you in reply:
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# chocolate.jpeg
There they are! Add them to your local Git repository so they’ll be tracked by Git.
git add chocolate.jpeg3
Now, take a “snapshot” of the repository as it stands now with the commit command:
git commit -m “Add chocolate.jpeg.”
Great! But your co-workers, hard at work in their own local repositories, can’t see your fantastic new design. That’s because the main project is stored in the company GitHub account (username: 123WebDesign) in the repository called “icecream.”
Since you haven’t connected to the GitHub repo yet, your computer doesn’t even know this exists. So tell your local repository about it:
git remote add origin https://github.com/123WebDesign/icecream.git5
And double check to make sure it knows:
git remote -v
Finally, it’s the moment you’ve been waiting for. Upload that delicious looking sundae up to the project:
git push
Ta da! With all of these tool at hand, it’s clear that Git and the GitHub service aren’t just for programmers.
Git Resources

CodeSchool's Try Git.
Git is dense, I know. I did my best to make a tutorial that could even teach me how to use it, but we don’t all learn in the same ways. Here are some resources I found useful while teaching myself how to use Git and GitHub over the summer:
- Pro Git. Here’s an entire open source book on learning and using Git. It looks like a long one, but I didn’t need to read anything past chapter three just to learn the basics.
- Try Git. CodeSchool and GitHub teamed up to make this speedy tutorial. If you want a little more practice with the basics, this should help. And if you have some extra money and want to learn everything there is to know about Git, Code School’s Git Real should do the trick.
- GitHub Guides. If you’re a visual learner, GitHub’s official YouTube channel is worth your time. I especially got a lot out of the Git Basics four-part series.
- Git Reference. Got the basics down but find yourself always forgetting the commands? This handy site is great as a glossary reference
- Git – the simple guide. This tutorial is short and sweet, but it was a little too fast for me as a beginner. If you want to refresh on the basics of Git, this should be all you need.
GitHub For Beginners: Commit, Push And Go的更多相关文章
- GitHub For Beginners: Don’t Get Scared, Get Started
It's 2013, and there's no way around it: you need to learn how to use GitHub.2 Why? Because it's a s ...
- 使用命令创建github代码仓库,push本地仓库到github远程代码仓库
1.利用命令创建github远程代码仓库 在将本地代码push到github远程代码仓库之前,总是需要新建github代码仓库,在将本地仓库关联到github远程仓库.其中最为繁琐的操作是建立gith ...
- android studio上传项目到github报错Successfully created project 'Demo' on GitHub, but initial commit failed:
今天博主正在愉快地学习在AndroidStudio中使用Git,结果报了下面这个错∑(っ°Д°;)っ: Can't finish GitHub sharing process Successfully ...
- 解决上传到github报错Successfully created project 'autotest' on GitHub, but initial commit failed:
通过IDEA上传代码到GitHub上可是有时候会碰到这样的问题. 当我们选择VCS->Import into Version Control->Share Project on GitHu ...
- 按正常步骤对github的仓库进行push自己本地的代码提示push rejected
按正常步骤对github的仓库进行push自己本地的代码提示push rejected. 大概原因是:初始化项目时,远程仓库我建了README.md文件,而本地仓库与远程仓库尚未进行文件关联,因此需要 ...
- Git CMD连接,管理(remote,add,commit,push)github repository
git initmd testcd testgit statusgit add test //git add test/a.txtgit status git remote add origin g ...
- 第二章-如何使用github建立一个HelloWorld项目,git的add/commit/push/pull/fetch/clone等基本命令用法。--答题人:杨宇杰
1.配置Git 首先在本地创建ssh 秘钥:在git bash输入: $ ssh-keygen -t rsa -C "your_email@youremail.com" eg:$ ...
- 2.每人自己建立一个HelloWorld项目,练习使用git的add/commit/push/pull/fetch/clone等基本命令。比较项目的新旧版本的差别。答题人:张立鹏
第1步:创建SSH Key.在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步.如果没有,打开Shell ...
- github 使用“git commit -m"命令时候出现的一个小问题
git commit -m 使用问题 今天提交文件到github,步骤是: git add abc.py (abc.py是我当前随意写的一个文件名) git commit -m 'add codes ...
随机推荐
- python的运维交流学习笔记
#!/usr/bin/env | #!/usr/bin/python#coding:gbk #python 运维练习 #需求: #1.利用python实现自动监控服务器性能 #2.并将监控到的数据进行 ...
- deeplearning.ai 改善深层神经网络 week2 优化算法 听课笔记
这一周的主题是优化算法. 1. Mini-batch: 上一门课讨论的向量化的目的是去掉for循环加速优化计算,X = [x(1) x(2) x(3) ... x(m)],X的每一个列向量x(i)是 ...
- 洛谷 P1553 数字反转(升级版)【字符串+STL stack】
P1553 数字反转(升级版) 题目描述 给定一个数,请将该数各个位上数字反转得到一个新数. 这次与NOIp2011普及组第一题不同的是:这个数可以是小数,分数,百分数,整数.整数反转是将所有数位对调 ...
- CF 610E. Alphabet Permutations
题目:http://codeforces.com/problemset/problem/610/E 如果存在c1,c2在原串相邻且在询问串中c1在c2前面的话,把它们在原串出现次数加起来记作sum,那 ...
- Windows下MYSQL读取文件为NULL
只记录解决问题的方法. mysql 版本: 5.7.18 问题: 在执行mysql 函数load_file时,该函数将加载指定文件的内容,存储至相应字段.如: SELECT LOAD_FILE(&qu ...
- 小工具:截图&简单图像处理
一.程序运行截图 二.获取屏幕截图的方法 首先知道我们可以通过Screen.PrimaryScreen.Bounds获取到当前整个屏幕,再利用Bitmap和Graphics就可以得到整个屏幕的图片了. ...
- LNMP安装Let’s Encrypt 免费SSL证书方法:自动安装与手动配置Nginx
前几天介绍了最新StartSSL免费SSL申请与配置,很多人看到部落介绍SSL证书安装时总是推荐了OneinStack,因为OneinStack提供了一键添加和配置Let's Encrypt 免费SS ...
- PHP和Python如何选择?或许可以考虑这三个问题
撤稿纠错 文/黄小天.李亚洲 (选自Hackernoon 机器之心编译) 2017 年可谓是网页应用与 API 之年,开发者不用每次重新发明轮子,而是利用脚手架和第三方库就能确保项目在几天内实时部署. ...
- 在Pycharm中运行Scrapy爬虫项目的基本操作
目标在Win7上建立一个Scrapy爬虫项目,以及对其进行基本操作.运行环境:电脑上已经安装了python(环境变量path已经设置好), 以及scrapy模块,IDE为Pycharm .操作如下: ...
- python3 第十章 - 如何进行进制转化
在计算机的世界里,2进制是主流,而在人类的自然世界中,10进制是主流,那么在这之间必然就会存在进制转化的问题.本章我们就来谈谈进制转化,也希望通过本章加深您对前些章所学知识的理解. 原理:先说说关于位 ...