Skip to content

Instantly share code, notes, and snippets.

@kofemann
Last active July 31, 2017 15:57
Show Gist options
  • Save kofemann/4ecc385e162dbcad70925ecb1c50425a to your computer and use it in GitHub Desktop.
Save kofemann/4ecc385e162dbcad70925ecb1c50425a to your computer and use it in GitHub Desktop.
Git tutorial for beginners

Hands on GIT

Get started

create your own fork and clone newly created repo:

$ git clone https://github.com/kofemann/dcache.git

By default, git creates branch with name master. When you clone, master branch will be checked out into your work space.

As we want to make some local commit's it's advised to have a dedicated branch:

$ git checkout -b my-new-contribution

The checkout commmand updates your workspace with version from specified branch. The -b flags tells git to create a new branch.

Lets go big

$ git init hands-on-git
$ cd hands-on-git
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
$ vi README.md
$ git status                                  (git)-[master] 
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	README.md

nothing added to commit but untracked files present (use "git add" to track)
$ git add README.md
$ git status                                  (git)-[master] 
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   README.md

$ git commit -m "Starting next big thing"
[master (root-commit) ffa14d9] Starting next big thing
 1 file changed, 2 insertions(+)
 create mode 100644 README.md
$ vi README.md
$ git status                                  (git)-[master] 
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:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff                                    (git)-[master] 
diff --git a/README.md b/README.md
index f1d910e..62aca13 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,6 @@
 This project will change my life
 ================================
+
+Howto contribute
+================
+This project uses GIT!
$ git add README.md
$ git commit
master 7c23a3e] docs: add a section on how to contribute
 1 file changed, 4 insertions(+)
$ git log                                     (git)-[master] 
commit 7c23a3efdf46a1787e0826275b94bedcc80fa60a (HEAD -> master)
Author: Tigran Mkrtchyan <[email protected]>
Date:   Thu Jul 27 22:13:14 2017 +0200

    docs: add a section on how to contribute

commit ffa14d908b2f199112bf03147e3f9e35162095af
Author: Tigran Mkrtchyan <[email protected]>
Date:   Thu Jul 27 22:06:44 2017 +0200

    Starting next big thing
$ git checkout -b build-instructions          (git)-[master] 
Switched to a new branch 'build-instructions'
$ git branch                      (git)-[build-instructions] 
* build-instructions
  master
$ vi BUILDING.md
$ git commit -m "docs: first touch to build instructions"
[build-instructions 1bd5763] docs: first touch to build instructions
 1 file changed, 2 insertions(+)
 create mode 100644 BUILDING.md
$ vi BUILDING.md
$ git commit -m "docs: list tools required for building"
[build-instructions 9952821] docs: list tools required for building
 1 file changed, 3 insertions(+)
$ git checkout master             (git)-[build-instructions] 
Switched to branch 'master'
$ git merge build-instructions                (git)-[master] 
Updating 7c23a3e..9952821
Fast-forward
 BUILDING.md | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 BUILDING.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment