Git
git init​
Make sure you are inside the webdev
folder. Then type git init
. This begins
a git project. If you type ls -lah
you'll see that it creates a secret .git
folder where it keeps track of everything (you don't have to look in there or do
anything with it.)
git status​
Type git status
. This will tell you that index.html
is an untracked file.
The way git is organized is that you group you changes into what are called commits. A commit is one group of changes that are made permanent. A git repository will have many commits. Some will have just one commit, some will have many. As of May 12, 2018, the git repository for the Linux project has 753,310 commits. A commit is made up of all the changes, the differences between where the code was and where the code is now. This will add new files, remove old files, delete some lines in some files, and add lines in others.
So let's make our first commit in this repository.
git add​
The way you add files to a commit is that they have to go through two stages:
being staged and then being committed. Type git add index.html
. This will make
index.html staged and ready to be committed. Type git status
and it will show
index.html as a change ready to be committed. You can also type git add .
to
make everything in this directory staged, or type git add -A
to add everything
and include anything you deleted to also be deleted from the repo.
git commit​
Type git commit -m "My first commit"
. It should tell you added your first
commit. Type git status
and it should tell you you haven't changed anything
since last commit. The -m
is important because each commit must have a message
with it and it's best to say what you did in that commit, something like "fixed
this bug" or "added this feature". If you forget the -m
it'll probably throw
you into vim, so be prepared!
Github​
Now, we're going to create our own Github repo.
Click the + (highlighted in red) in the nav and create a new repository. Name the new repo whatever you would like, do not add the license or README, and continue.
git remote​
Back to your terminal, navigate to your project using cd
and write the
following command: git remote add origin <your project url here>
. Notice about
half way down the page you can see that command, feel free to copy and paste
that.
- you can also find your project url here:
This command is going to add a new remote to your project called origin
. A
remote is somewhere for you to push your computer. If you use a Github-based
flow (most of us do) this will be one of the very few remotes you'll ever use.
git can be used in a more decentralized way; you could have a remote that's your
buddy's computer. But I've never worked that way. We called the remote "origin"
but we could have called it anything. But everyone calls it origin. "origin"
should always be called where your repo is. Sometimes you'll fork someone
else's code and keep track of that repo too, and typically you'd call that
"upstream".
Type git remote -v
and you should see your newly-added remote. It adds the
remote twice because you can fetch (which is what you call when you pull code
down) from one place and you can push (which is what you call when you send your
code up) to another. I've never seen anyone do that though.
git push​
Okay, now that we're here, type git push origin main
. push
is the command
to send your code up to Github origin
is the name of the remote that we just
added. main
is the name of the branch that we're on. git has the ability to
keep track of multiple branches of code so that you and your colleague can work
on the same code at the same time but each keep your own copy. For now we're
working out of the main branch which the main branch that everyone will
eventually merge their code into.
more git​
git is so powerful. There are a lot of really cool features. Probably the
biggest thing we didn't talk about here is merging code with others. See
Nina Zakharenko's course to
become a git master. Some other basic functions you'll want to learn is how to
git log
git pull
, git clone
, git merge
, git rebase
, git stash
,
git checkout
, and git branch
. Those are the ones that are needed for base
level proficiency in git. There are many more commands that make git an integral
tool to comprehend, but the important ones for the course are the ones mentioned
here.
Github Pages​
Github Pages is a service provided by Github to allow users to host website for free! It's also very simple and straightforward to use.
First of all, make sure that on your Github repo, you have your index.html
in
place.
Next, Go to Settings
⇒ Pages
, and then select the Github pages option. You
should see this:
Wait a few minutes, and then click on the url to your site, you should see something like this: