Do you have trouble committing? In this episode
of GitHub Foundations, we're gonna look at three different ways
to make a commit in Git.
[GitHub & Git Foundations]
♪(easy listening music)♪
[Commit]
Hi, I'm Tim Berglund. The whole point of using
a source control system is to keep track of changes. In Git,
these are called commits. Here, we're gonna look at three
different ways to make a commit.
[Commit: Command Line]
We'll start at our local computer, down at the command line.
Now suppose you've already got a project that you've started on.
It doesn't matter what the language or platform is, just as long as
it's text files arranged in directories. Now you're gonna
use a text editor to make a change to one of those files,
or maybe you'll change a few at once. The "git status" command
is gonna tell you about what files might need to be committed.
It's gonna tell you about files that have changed, or maybe
new files that you've added since the last commit.
To take those changes and get them ready to be committed,
use the "git add" command. This puts them in a special
holding tank called the staging area. You can see that they've
moved to the staging area by using the "status" command
again, and notice that the output looks different.
Every time you commit a change, it has to go through
the staging area. This is a key part of Git's architecture.
It can seem strange at first, but the more you use Git,
the more sense it will make. To complete the process,
use the "git commit" command. Be sure to include a nice
descriptive message so that other people can understand
what this commit is all about. If you don't include a message,
Git will actually open a text editor and make you enter one.
It's not gonna let you get away with making a commit
without describing it. You should notice this: if you were to
edit that same file a second time, you'd actually use the "git add"
command again before committing it, and then,
with the file stage, you'd use the "git commit" command again
to take another snapshot of your changes. In a real project,
a lot of the time, you'll change many files at once.
The staging area gives you the flexibility to decide
what changes become a part of what commit. And as you
get more and more comfortable using Git, you're gonna
start to pay attention to the way you craft commits.
Each one should be a coherent story that makes sense
to another person looking at your history. It's not just
a jumble of changes that you happen to have made since
the last time you've committed. Don't worry if this
doesn't make sense yet. It'll start to make a lot more sense
as use Git more and more together
with other people.
[Commit: GitHub.com]
Now, what if you've already got a project up on GitHub.com?
Well, you can make commits there too. Click on the file
you want to edit, and then click the "edit" button
in the browser. You'll get a simple text editor where
you can make changes to your file. When you submit
those changes, GitHub will create a new commit containing
just the changes to that file. Doing it this way, you don't have
quite as much control over what goes into each commit,
but it's a lot easier to do for people who aren't comfortable
using the command line, and for making really simple
changes to text files.
[Commit: GitHub for Mac / Windows]
Finally, maybe back on your computer, you can commit code
using GitHub for Desktop. This still makes a commit locally
on your computer, but without forcing you to use
the command line. You edit your files with a text editor
the way you normally would, but now, GitHub for Desktop,
and I'm showing you the Mac version here, will let you select
which files you want to stage and then commit.
You can easily select the files you want to be in the commit
and type in the message, and GitHub for Desktop handles
the add and the commit for you. This is another great way
to go if you want to steer clear of the command line for
everyday operations. Commits are the cornerstone of collaboration
with Git and GitHub. In future episodes, we'll look at how
to examine the commits you have locally, and, the best part,
how to share them with other people.
[Thanks for watching.]
Thanks for watching this episode of GitHub Foundations
on how to commit. If you like this, subscribe
to the GitHub Guides channel here. If you want to see
other things we've got going on with videos at GitHub,
check out our other channels down here.
As always, we would love if you left us a comment or
a question down here, and if you want to see more
training videos, just click on one of these guys
down here; we got them ready for you.