Start working on a new issue - I

$ git status
On branch master
nothing to commit, working directory clean

$ git checkout -b bug/fix-nasty-bug
Switched to a new branch 'bug/fix-nasty-bug'

$ git status
On branch bug/fix-nasty-bug
nothing to commit, working directory clean

$ touch debian.txt
$ touch redhatlinux.txt
$ touch opensuse.txt

$ git status
On branch bug/fix-nasty-bug
Untracked files:
  (use "git add <file>..." to include in what will be committed)

	debian.txt
	opensuse.txt
	redhatlinux.txt

nothing added to commit but untracked files present (use "git add" to track)

Start working on a new issue - II

$ git add "*.txt"
Marias-MacBook-Air:myproject marianita$ git status
On branch bug/fix-nasty-bug
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	new file:   debian.txt
	new file:   opensuse.txt
	new file:   redhatlinux.txt

$ git commit -m "Add Linux distribution files"
[bug/fix-nasty-bug 51a66c1] Add Linux distribution files
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 debian.txt
 create mode 100644 opensuse.txt
 create mode 100644 redhatlinux.txt

Start working on a new issue - III

$ git log --summary
commit 51a66c17cc2f2f9aeec81eaa9aa1f06d2db1ab59
Author: Maria Nita <maria.nita.dn@gmail.com>
Date:   Fri Mar 25 19:53:20 2016 +0200

    Add Linux distribution files

 create mode 100644 debian.txt
 create mode 100644 opensuse.txt
 create mode 100644 redhatlinux.txt

commit bc7e30f85dfe5e63dd20c57ed96491a80a5eb90a
Author: Maria Nita <maria.nita.dn@gmail.com>
Date:   Fri Mar 25 19:32:05 2016 +0200

    Add initial commit - add readme

 create mode 100644 README.md

$ echo 'ubuntu, kubuntu, archlinux' > debian.txt

$ git status
On branch bug/fix-nasty-bug
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:   debian.txt

no changes added to commit (use "git add" and/or "git commit -a")

Start working on a new issue - IV

$ git diff
diff --git a/debian.txt b/debian.txt
index e69de29..d7fc021 100644
--- a/debian.txt
+++ b/debian.txt
@@ -0,0 +1,3 @@
+ubuntu, kubuntu, archlinux

$ git add .
$ git status
On branch bug/fix-nasty-bug
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   debian.txt

$ git diff
$ git diff --staged
diff --git a/debian.txt b/debian.txt
index e69de29..d7fc021 100644
--- a/debian.txt
+++ b/debian.txt
@@ -0,0 +1,3 @@
+ubuntu, kubuntu, archlinux

$ git commit -m "Add debian distributions"
[bug/fix-nasty-bug b098945] Add debian distributions
 1 file changed, 3 insertions(+)

$ git push origin bug/fix-nasty-bug

Tips & Tricks

New branch: git checkout -b branch-name

Track file:

  • git add file.txt  
  • git add '*.txt'
  • git add directory/
  • git add .

Commit file:

  • git commit -m "Just commit tracked files"
  • git commit -am "Add all files and then commit"

See changes:

  • git diff
  • git diff --staged

Merge vs Rebase - I


$ git checkout -b feature-one
Switched to a new branch 'feature-one'
$ echo suselinuxenterprise, linkat > opensuse.txt
$ git commit -am "Add opensuse distributions"
[feature-one cdf8ede] Add opensuse distributions
 1 file changed, 1 insertion(+)

$ git checkout -
$ git checkout -b feature-two
Switched to a new branch 'feature-two'
$ ls
README.md	debian.txt	opensuse.txt	redhatlinux.txt
$ echo 'centos, fedora' > redhatlinux.txt
$ git commit -am "Add RedHat Linux distributions"
[feature-two c6ca69a] Add RedHat Linux distributions
 1 file changed, 1 insertion(+)


$ git checkout master
$ git log --summary
commit 9e58b545f748b283ceebb3c711c9d81cf593cd61
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add debian distributions

commit 6b1e9d299a072ee91c52db501a94a94a40b1a6f0
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add Linux distribution files

commit 7fd92e358aa9a8bd86c49cc124846a7ba05a0506
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add initial commit -add readme

Merge your issue - I

$ git checkout master
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

$ ls
README.md	debian.txt	opensuse.txt	redhatlinux.txt

$ git merge feature-one
Updating 9e58b54..dbd774c
Fast-forward
 opensuse.txt | 1 +
 1 file changed, 1 insertion(+)

$ git log --summary
commit dbd774ccd413ed8c4aba8977b114b5746a7d8dc2
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add opensuse distributions

commit 9e58b545f748b283ceebb3c711c9d81cf593cd61
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add debian distributions

commit 6b1e9d299a072ee91c52db501a94a94a40b1a6f0
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add Linux distribution files

commit 7fd92e358aa9a8bd86c49cc124846a7ba05a0506
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add initial commit -add readme

Merge your issue -  II

$ git merge feature-two
Merge made by the 'recursive' strategy.
 redhatlinux.txt | 1 +
 1 file changed, 1 insertion(+)

$ git log --summary
commit fb034b46a7c2ab617b203ca54ac352bc91b975a7
Merge: dbd774c 7d216b0
Author: Maria Nita <maria.nita.dn@gmail.com>
    Merge branch 'feature-two'

commit 7d216b0a42e740599056d82752c35f4ae0305576
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add RedHat Linux distributions

commit dbd774ccd413ed8c4aba8977b114b5746a7d8dc2
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add opensuse distributions

commit 9e58b545f748b283ceebb3c711c9d81cf593cd61
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add debian distributions

commit 6b1e9d299a072ee91c52db501a94a94a40b1a6f0
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add Linux distribution files

commit 7fd92e358aa9a8bd86c49cc124846a7ba05a0506
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add initial commit -add readme

Rebase your issue - I

$ git checkout feature-one
Switched to branch 'feature-two'

$ git branch -D master
Deleted branch master (was fb034b4).

$ git fetch origin master:master
From github.com:rosedu-cdl/myproject
 * [new branch]      master     -> master

$ git checkout master

$ git rebase feature-one
First, rewinding head to replay your work on top of it...
Fast-forwarded master to feature-one.

$ git log --summary
commit dbd774ccd413ed8c4aba8977b114b5746a7d8dc2
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add opensuse distributions


commit 9e58b545f748b283ceebb3c711c9d81cf593cd61
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add debian distributions
....

Rebase your issue - II

$ git rebase feature-two
First, rewinding head to replay your work on top of it...
Applying: Add opensuse distributions

$ git log --summary
commit 22b26314428d69b3efbc5d3db17ef4f71391b47d
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add opensuse distributions


commit 7d216b0a42e740599056d82752c35f4ae0305576
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add RedHat Linux distributions


commit 9e58b545f748b283ceebb3c711c9d81cf593cd61
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add debian distributions
.....

Rebase your issue - III

$ git rebase feature-one
First, rewinding head to replay your work on top of it...
Fast-forwarded master to feature-one.

$ git log --summary
commit 800d4c77400c23cfed424d0b4df568d11177b1a4
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add RedHat Linux distributions


commit cdf8ede7554d3428a04cd9a651e6b7620e15439f
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add opensuse distributions

commit 9e58b545f748b283ceebb3c711c9d81cf593cd61
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add debian distributions

commit 6b1e9d299a072ee91c52db501a94a94a40b1a6f0
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add Linux distribution files

commit 7fd92e358aa9a8bd86c49cc124846a7ba05a0506
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add initial commit -add readme

Tips & Tricks

Checkout

  • git checkout -
  • git checkout branch-name

 

Delete branch: git branch -D branch-name

Get a branch from GitHub: git fetch origin master:master

 

Merge your work:

  • git merge branch-name
  • git rebase branch-name

 

Push your work to Github: git push origin branch-name

Remove change commits - I

$ git checkout master
$ git log --summary
commit 22b26314428d69b3efbc5d3db17ef4f71391b47d
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add opensuse distributions


commit 7d216b0a42e740599056d82752c35f4ae0305576
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add RedHat Linux distributions


commit 9e58b545f748b283ceebb3c711c9d81cf593cd61
Author: Maria Nita <maria.nita.dn@gmail.com>
    Add debian distributions

$ git rebase -i HEAD~4
pick 6b1e9d2 Add Linux distribution files
edit 9e58b54 Add debian distributions
pick 7d216b0 Add RedHat Linux distributions
pick 22b2631 Add opensuse distributions
# Rebase 7fd92e3..22b2631 onto 7fd92e3 (4 command(s))


Stopped at 9e58b545f748b283ceebb3c711c9d81cf593cd61... Add debian distributions
You can amend the commit now, with
	git commit --amend

Once you are satisfied with your changes, run
	git rebase --continue

Remove change commits - II

$ git status
interactive rebase in progress; onto 7fd92e3
Last commands done (2 commands done):
   pick 6b1e9d2 Add Linux distribution files
   e 9e58b54 Add debian distributions
Next commands to do (2 remaining commands):
   pick 7d216b0 Add RedHat Linux distributions
   pick 22b2631 Add opensuse distributions
  (use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'master' on '7fd92e3'.
  (use "git commit --amend" to amend the current commit)
  (use "git rebase --continue" once you are satisfied with your changes)

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:   debian.txt

no changes added to commit (use "git add" and/or "git commit -a")

$ git diff
diff --git a/debian.txt b/debian.txt
index bda17f1..50a6822 100644
--- a/debian.txt
+++ b/debian.txt
@@ -1 +1 @@
-ubuntu, kubuntu, archlinux
+ubuntu, kubuntu

Remove change commits - III

$ git add .
$ git commit --amend
[detached HEAD 54da4c8] Add debian distributions
 Date: Sat Mar 26 07:41:29 2016 +0200
 1 file changed, 1 insertion(+)

$ git rebase --continue
Successfully rebased and updated refs/heads/master.

$ git status On branch master
nothing to commit, working directory clean

$ git log --summary
192-168-0-102:myproject marianita$ git log
commit 07d00a7a25bf8cd257d404b01319865752926d78
    Add opensuse distributions

commit 511257b5e245a8dc82a4554d5551a598ba1f3dd7
    Add RedHat Linux distributions

commit 54da4c88971311973c9be5618a52183ed0c18911
    Add debian distributions

$ cat debian.txt
ubuntu, kubuntu

Remove a commit


$ git log --summary
192-168-0-102:myproject marianita$ git log
commit 07d00a7a25bf8cd257d404b01319865752926d78
    Add opensuse distributions

commit 511257b5e245a8dc82a4554d5551a598ba1f3dd7
    Add RedHat Linux distributions

commit 54da4c88971311973c9be5618a52183ed0c18911
    Add debian distributions

$ git rebase --onto 511257b^ 511257b
First, rewinding head to replay your work on top of it...
Applying: Add opensuse distributions

$ git log --summary
commit a8f6a1191b6bbd0a4c86d5c545c4cfe8aa5b0ee2
    Add opensuse distributions


commit 54da4c88971311973c9be5618a52183ed0c18911
    Add debian distributions


commit 6b1e9d299a072ee91c52db501a94a94a40b1a6f0
    Add Linux distribution files

$ cat redhatlinux.txt

Squash two commits - I


$ git log --summary
192-168-0-102:myproject marianita$ git log
commit 07d00a7a25bf8cd257d404b01319865752926d78
    Add opensuse distributions

commit 54da4c88971311973c9be5618a52183ed0c18911
    Add debian distributions

commit 6b1e9d299a072ee91c52db501a94a94a40b1a6f0
    Add Linux distribution files

$ git rebase -i HEAD~3
pick 6b1e9d2 Add Linux distribution files
squash 54da4c8 Add debian distributions
pick a8f6a11 Add opensuse distributions
# Rebase 7fd92e3..a8f6a11 onto 7fd92e3 (3 command(s))
...
# s, squash = use commit, but meld into previous commit

### Save file

Squash two commits - II


# This is a combination of 2 commits.
# The first commit's message is:

Add Linux distribution files

# This is the 2nd commit message:

Add debian distributions

# Please enter the commit message for your changes. Lines starting
...

---------

# This is a combination of 2 commits.
# The first commit's message is:

Add Linux distribution and debian distributions files

----------

### Save file
$ 
[detached HEAD 88e9694] Add Linux distribution and debian distributions files
 Date: Sat Mar 26 07:39:33 2016 +0200
 3 files changed, 1 insertion(+)
 create mode 100644 debian.txt
 create mode 100644 opensuse.txt
 create mode 100644 redhatlinux.txt
Successfully rebased and updated refs/heads/master.

Squash two commits - III

$ git log --summary
commit d8e1474bb90148bf17fae18b1d6f09a29b558336
Author: Maria Nita <maria.nita.dn@gmail.com>
Date:   Sat Mar 26 08:12:11 2016 +0200

    Add opensuse distributions


commit 88e9694b734cb9139590ff7d5b98d71edf4024ee
Author: Maria Nita <maria.nita.dn@gmail.com>
Date:   Sat Mar 26 07:39:33 2016 +0200

    Add Linux distribution and debian distributions files

 create mode 100644 debian.txt
 create mode 100644 opensuse.txt
 create mode 100644 redhatlinux.txt

$ cat debian.txt
ubuntu, kubuntu

Tips & Tricks

Append to previous commit

  1. git add .
  2. git commit --amend

Remove a commitgit rebase --onto SHA^ SHA

Edit a commit:

  1. git rebase -i HEAD~No
  2. select edit
  3. edit, add, commit

Squash a commit:

  1. git rebase -i HEAD~No
  2. select squash
  3. choose commit message and save

 

I want to

start a new project

I want to start a new project

$ cd ~/

$ mkdir myproject

$ cd myproject

$ git init
Initialized empty Git repository in ~/myproject/.git/

$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

Create a directory / project and init git

I want to start a new project

Create a Repository on GitHub with the same name

I want to start a new project

$ cd ~/myproject

$ git remote -v
$ git remote add origin git@github.com:rosedu-cdl/myproject.git
$ git remote -v
origin	git@github.com:rosedu-cdl/myproject.git (fetch)
origin	git@github.com:rosedu-cdl/myproject.git (push)

$ git status
On branch master

Initial commit
nothing to commit (create/copy files and use "git add" to track

$ touch README.md

$ git status
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)

Connect the local project / directory with the Github project

I want to start a new project

$ git add README.md
$ git status
On branch master

Initial commit

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

	new file:   README.md

$ git commit -m "Add initial commit - add readme"
[master (root-commit) bc7e30f] Add initial commit - add readme
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md


$ git log --summary
commit bc7e30f85dfe5e63dd20c57ed96491a80a5eb90a
Author: Maria Nita <maria.nita.dn@gmail.com>
Date:   Fri Mar 25 19:32:05 2016 +0200

    Add initial commit - add readme

 create mode 100644 README.md

$ git push -u origin master

Make your first commit

I want to start a new project

See your first commit on GitHub

Tips & Tricks

See what's your branch and changes: git status

Track a file: git add file-name

Commit tracked files: git commit -m "Message"

See what you have committed: git log

 

Set a remote project:

  1. git remote -v
  2. git remote add name url

 

Get changes from remote: git pull remote-name branch-name

Push changes to remote: git push remote-name branch-name

I want to get a  project from GitHub

I want to get a project from GitHub

Go to the Repository page and copy the clone URL

I want to get a project from GitHub

$ cd ~/

$ git clone git@github.com:rosedu-cdl/myproject.git
Cloning into 'myproject'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

$ ls
myproject

$ cd myproject

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

$ git remote -v
origin	git@github.com:rosedu-cdl/myproject.git (fetch)
origin	git@github.com:rosedu-cdl/myproject.git (push)

$ ls
README.md

Clone the project on your laptop and start contributing

I want to fork a project from GitHub

I want to fork a project from GitHub

Fork repository from upstream project

I want to fork a project from GitHub

Now you have a copy of the repository

I want to fork a project from GitHub

$ cd ~/

$ git clone git@github.com:rosedu-cdl/cdl.git
Cloning into 'cdl'...
remote: Counting objects: 796, done.
remote: Total 796 (delta 0), reused 0 (delta 0), pack-reused 796
Receiving objects: 100% (796/796), 27.43 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (299/299), done.
Checking connectivity... done.

$ cd cdl
$ git remote -v
origin	git@github.com:rosedu-cdl/cdl.git (fetch)
origin	git@github.com:rosedu-cdl/cdl.git (push)

$ git remote add upstream git@github.com:rosedu/cdl.git
origin	git@github.com:rosedu-cdl/cdl.git (fetch)
origin	git@github.com:rosedu-cdl/cdl.git (push)
upstream	git@github.com:rosedu/cdl.git (fetch)
upstream	git@github.com:rosedu/cdl.git (push)

$ git pull upstream master

$ git push origin master

Clone your project on your laptop and add upstream remote

I want to fork a project from GitHub

$ cd ~/cdl

$ git checkout -b new-bug-fix
Switched to a new branch 'new-bug-fix'

$ touch filewhichfixesbug.html
$ git add filewhichfixesbug.html

$ git commit -m "Add fix for bug"
[new-bug-fix 074a978] Add fix for bug
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 filewhichfixesbug.html

$ git pull upstream master
From github.com:rosedu/cdl
 * branch            master  -> FETCH_HEAD
Already up-to-date.

$ git push origin new-bug-fix

Always push to your repo (origin) and pull for updates from upstream (upstream)

I want to fork a project from GitHub

Create Pull Request from your repository to the upstream project

I want to fork a project from GitHub

Now you wait for review :)

Git

By Maria Niţă