Working with Git and GitHub - Webbprogrammering/websoft GitHub Wiki
Here is a basic work flow when you work with Git and GitHub.
Lets start with an overview of some basic commands.
Command | What |
---|---|
git status |
Do a healthcheck and see how you local changes reflect to the current repo and its master. |
git add <filename> |
Add a specific file to the repo. |
git add . |
Add all files in the current directory. |
git commit -a -m "Message" |
Commit all -a changes to the repo and attach a commit message -m "Message" . |
git push |
Push all committed changes to your master on GitHub. |
git pull |
Update your local repo with and files changed on the master. Useful then updating the repo from several places. |
git tag -a v1.0.0 -m "Message" |
Add a tag to your repo and attach a tag message. |
git push --tags |
Push the tags to your master on GitHub. |
The commands are further explained below.
You have installed Git and you hav forked a copy of the course repo to your own account on GitHub. You have cloned your forked course repo and its available on your local disk and you have created the work
directory. All this was done in the "Lab & Development Environment".
Use the terminal Git Bash, or similair.
You can check a status of a repo.
git status
It is sort of a health check on the repo and it compares your local version (your local branch master) with the remote version on GitHub (your origin/master).
Go to your repo and create a new directory work/s01
and move into it.
# Go to the course repo
cd work
mkdir s01
cd s01
touch try.html
ls -l
Note that cd ..
moves one directory up in the direcotry hierachy.
You can open the file in your texteditor and add some sample text into it, just for the fun of it.
Use git status
to see how it looks.
We shall now add the file to the repo.
git add try.html
The file is added to the repo.
An alternative is git add .
which add all files in the current directory.
You can now do another git status
.
When you are done with all your additions, and changes, then you shall commit them. It is like permanent writing your updates into the repo.
git commit -a -m "First commit"
The switches -a
means all files changed and -m "First commit"
is a commit-message attached to this commit, explaining what the commit was about.
You can the check with git status
.
When you are done with all commits you should push them all to GitHub.
git push
The changes are now uploaded to GitHub and you can reload your repo page on GitHub to check that all changes was uploaded.
Check your git status
.
You are now up to date with your master.
If there are changes to the master that you have not yet downloaded locally, then do like this.
git pull
Your local repo is then updated to mirror the master.
When you have a certain baseline in your project, you mey want to tag it with a version number. This makes it easier to know tha status of the repo.
git tag -a v1.0.0
git push --tags
You can add a new tag at any stage.