For this example, I’ll use my binoculars page to demo the basic commands I use to track changes and move code between my laptop, github and my server.
In a new project folder
1 2 3 4 5 6 7 8 9 10 11 12 |
$ git init Initialized empty Git repository $ git add . $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: index.html |
Make some changes and save them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: index.html Untracked files: (use "git add <file>..." to include in what will be committed) binoculars.png hummingbird.png $ git add -A $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: binoculars.png new file: hummingbird.png new file: index.html $ git commit -m "initial commit" [master (root-commit) 9fb8744] initial commit 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 binoculars.png create mode 100644 hummingbird.png create mode 100644 index.html |
I went down a rabbit hole and I wanna go home
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ git add -A $ git commit -m "Change is good" [master 429e7e8] change is good 1 file changed, 9 insertions(+) // Make some bad choices // Let's start over $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: index.html $ git checkout -- . $ git status On branch master nothing to commit, working tree clean |
Create a branch to track bug fix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ git branch BigBigFix $ git checkout BigBugFix Switched to branch 'BigBugFix' // fix it $ git commit -am "Fixed Big Bug" [BigBugFix 0989458] fixed Big Bug 1 file changed, 1 deletion(-) $ git checkout master Switched to branch 'master' $ git merge BigBugFix Updating 2987c5a..0989458 Fast-forward index.html | 1 - 1 file changed, 1 deletion(-) |
Put this gem in GitHub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ git remote add origin https://github.com/BrownCasey/Binoculars.git $ git push -u origin master Enumerating objects: 43, done. Counting objects: 100% (43/43), done. Delta compression using up to 8 threads. Compressing objects: 100% (43/43), done. Writing objects: 100% (43/43), 6.39 MiB | 387.00 KiB/s, done. Total 43 (delta 9), reused 0 (delta 0) remote: Resolving deltas: 100% (9/9), done. To https://github.com/BrownCasey/Binoculars.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'. // If your repo added a LICENSE (or other) file not in the project // you'll need to pull --rebase first, then git push // i.e. git pull --rebase origin master |
Make Dolly proud
Clone repo to web server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ cd www/html $ sudo mkdir binoculars $ cd binoculars $ sudo git clone https://github.com/BrownCasey/Binoculars . Cloning into '.'... remote: Enumerating objects: 43, done. remote: Counting objects: 100% (43/43), done. remote: Compressing objects: 100% (34/34), done. remote: Total 43 (delta 9), reused 43 (delta 9), pack-reused 0 Unpacking objects: 100% (43/43), done. Checking connectivity... done. // after some changes $ sudo git pull origin master From https://github.com/BrownCasey/Binoculars * branch master -> FETCH_HEAD |