The natural way normal people think about managing versions of a document is to save a copy with a new name that somehow shows which version is most recent.
The natural way developers used to think about managing versions of a document is to have a master copy somewhere. Everyone asks the server for the master copy, makes some changes, and then checks those changes back in.
This is not how Git works.
Git is distributed, meaning that every computer where git is installed has its own master copy.
So every computer has a full history of any git project (aka. repository or ‘repo’). Indeed, you don’t have to synchronise your repo with any other computer or server at all! 1
GitHub is nothing special to Git, just another Git server with which to negotiate changes. Do not think of GitHub as the ‘master’ copy. There isn’t one.
There are, however, upstream and remote repositories.
But Dropbox doesn’t have the .gitignore
file!
Term | Means |
---|---|
Repository (Repo) | A project or achive stored in Git. |
init | To create a new repo on your computer. |
clone | To make a full copy of a repo somewhere else. |
This creates a local repo that is unsynchronised with anything else:
Whereas this creates a local clone that is fully synchronised with GitHub:
Term | Means |
---|---|
add |
Add a file to a repo. |
mv |
Move/Rename a file in a repo. |
rm |
Remove a file from a repo. |
For example:
cd test # Back into the new Repo
touch README.md # Create empty file called README.md
git add README.md # Add it to the repository
git mv README.md fileA.md # Rename it (move it)
git rm fileA.md # Remove it... which is an Error!
This produces:
Term | Means |
---|---|
diff |
Show changes between commits. |
status |
Show status of files in repo. |
log |
Show history of commits. |
For example:
This produces:
Term | Means |
---|---|
commit |
To record changes to the repo. |
branch |
Create or delete branches. |
checkout |
Jump to a different branch. |
For example:
You should see:
[master (root-commit) e7a0b25] Added and then renamed the README Markdown file.
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 fileA.md
# ... and then this:
On branch master
nothing to commit, working tree clean
Make a note of the number after ‘root-commit’!
Term | Means |
---|---|
pull |
To request changes on a repo from another computer. |
push |
To send changes on a repo to another computer. |
For example:
git push
push
ed. If you forget to push
your changes (e.g. to GitHub) then you are not backed up if your computer dies.
So your workflow should be:
git add <filename.ipynb>
to record changes to the notebook (Note: replace <filename.ipynb>
completely with the notebook filename).git commit -m "Adding notes based on lecture"
(or whatever message is appropriate: -m
means ‘message’).git push
to push the changes to GitHub.If any of those commands indicate that there are no changes being recorded/pushed then it might be that you’re not editing the file that you think you are (this happens to me!).
On the GitHub web site you may need to force reload the view of the repository: Shift
+ the Reload button usually does it in most browsers. You may also need to wait 5 to 10 seconds for the changes to become ‘visible’ before reloading. It’s not quite instantaeous.
Getting to Grips with Git • Jon Reades