# GitHub

# Current Strategy

# Rebase instead of Merge

  1. Sync the remote master

    git pull

  2. Checkout to a new branch so all your commit don't disrupt the master branch

    git checkout -b feature_branch

  3. Work and commit as many times as you want, other people can work on the master branch while you are working on the feature branch

  4. Checkout to master and do a git pull

    git checkout master

    git pull

  5. Checkout to the feature branch and Rebase

    git checkout feature_branch

    git rebase master

  6. Checkout to master branch and Rebase feature branch. Or interative rebase for squash

    git checkout master

    git rebase feature_branch

  7. Squash your commits (Advanced), or

    git rebase -i HEAD~3

pick 7f9d4bf Accessibility fix for frontpage bug
pick 3f8e810 Updated screenreader attributes
pick ec48d74 Added comments & updated README
 
# Rebase 4095f73..ec48d74 onto 4095f73 (3 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
...
1
2
3
4
5
6
7
8
9
10
11
12

To combine change pick to squash as below

pick 7f9d4bf Accessibility fix for frontpage bug
squash 3f8e810 Updated screenreader attributes
squash ec48d74 Added comments & updated README
1
2
3

Then Edit the message by #commenting the messages you don't want.

# This is a combination of 3 commits
# This is the 1st commit message:

Accessibility fix for frontpage bug

# This is the commit message for #1:

Updated screenreader attributes

# This is the commit message for #2:

Added comments & updated README

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# This is a combination of 3 commits
# This is the 1st commit message:

Accessibility fix for frontpage bug

# This is the commit message for #1:

# Updated screenreader attributes

# This is the commit message for #2:

# Added comments & updated README

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# CheatSheet





# Minimal Configuration:

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/MASTERS
$ git config --global user.name "Thiago Souto"

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/MASTERS
$ git config --global user.email "thiago.souto@yahoo.com.br"
1
2
3
4
5

Opening git own config file with default editor

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/MASTERS
$ git config --global -e
hint: Waiting for your editor to close the file...
1
2
3

# 4️⃣ The Basics

# Initialization

Creating a folder for all git projects at the desktop

 


ls -al
mkdir GitProjects
1
2

pwd shows the path ls -al shows all the files and folders

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ pwd
/c/Users/Thiago Souto/Desktop/GitProjects
1
2
3

# Creating a new repository within the GitProjects folder

git init

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ git init demo
Initialized empty Git repository in C:/Users/Thiago Souto/Desktop/GitProjects/demo/.git/

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ cd demo

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls -al
total 4
drwxr-xr-x 1 Thiago Souto 197121 0 Dec 20 09:19 ./
drwxr-xr-x 1 Thiago Souto 197121 0 Dec 20 09:19 ../
drwxr-xr-x 1 Thiago Souto 197121 0 Dec 20 09:19 .git/
1
2
3
4
5
6
7
8
9
10
11
12
13

# Git States - The Basic Workflow

Local Git States

# First Commit

Checking status of the repository

git status


 






Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
1
2
3
4
5
6
7

Creating a new file on VisualStudio from git bash

code


 

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code README.md
1
2

Checking the file

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master

No commits yet

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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

TIP

To move the file from the working directory to the staging area lets do a git add

git add

This will move the file from working directory to staging area


 











Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   README.md
1
2
3
4
5
6
7
8
9
10
11
12

Finally to commit the file with a commit message we do

git commit -m "message"

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -m "first file in demo repo"
[master (root-commit) ed17cf2] first file in demo repo
 1 file changed, 4 insertions(+)
 create mode 100644 README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

1
2
3
4
5
6
7
8
9
10
11

# Repository

The .git folder is a special directory that git manages internally.

Don't play around with it unless you know what you are doing.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ cd .git/

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo/.git (GIT_DIR!)
$ ls -al
total 13
drwxr-xr-x 1 Thiago Souto 197121   0 Dec 20 09:44 ./
drwxr-xr-x 1 Thiago Souto 197121   0 Dec 20 09:34 ../
-rw-r--r-- 1 Thiago Souto 197121  24 Dec 20 09:43 COMMIT_EDITMSG
-rw-r--r-- 1 Thiago Souto 197121 130 Dec 20 09:19 config
-rw-r--r-- 1 Thiago Souto 197121  73 Dec 20 09:19 description
-rw-r--r-- 1 Thiago Souto 197121  23 Dec 20 09:19 HEAD
drwxr-xr-x 1 Thiago Souto 197121   0 Dec 20 09:19 hooks/
-rw-r--r-- 1 Thiago Souto 197121 137 Dec 20 09:43 index
drwxr-xr-x 1 Thiago Souto 197121   0 Dec 20 09:19 info/
drwxr-xr-x 1 Thiago Souto 197121   0 Dec 20 09:43 logs/
drwxr-xr-x 1 Thiago Souto 197121   0 Dec 20 09:43 objects/
drwxr-xr-x 1 Thiago Souto 197121   0 Dec 20 09:19 refs/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

If this folder is removed this is not a git repository anymore

To remove the folder we can rm -rf .git

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo/.git (GIT_DIR!)
$ cd ..

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ rm -rf .git

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo
$ git status
fatal: not a git repository (or any of the parent directories): .git
1
2
3
4
5
6
7
8
9

# Starting with Existing Project

TIP

On the folder jus do a git init . (the dot specifies to initialize on the current folder)

git init .

The dot means "This current folder"

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo
$ git init .
Initialized empty Git repository in C:/Users/Thiago Souto/Desktop/GitProjects/demo/.git/

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master

No commits yet

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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# Commits and Messages

Creating a new file and add everything to stage area

















Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code LICENSE.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master

No commits yet

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

nothing added to commit but untracked files present (use "git add" to track)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

git add .

wild card character "." indicates that I want all the files on this current folder added to the git staging area.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add .

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master

No commits yet

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14

Committing both files and writing a message for the commit on the text editor

git commit

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit
hint: Waiting for your editor to close the file...
[master (root-commit) 30b68b1] Committing a README and a LICENSE files
 2 files changed, 7 insertions(+)
 create mode 100644 LICENSE.md
 create mode 100644 README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12

# Log and Show Commit details

git log

Git responds with all the commits that are part of this repository


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git log
commit 30b68b19d2f952192faa25500af6fd4652f24b4c (HEAD -> master)
Author: Thiago Souto <thiago.souto@yahoo.com.br>
Date:   Fri Dec 20 10:22:03 2019 +1300

    Committing a README and
    a LICENSE files
1
2
3
4
5
6
7
8
9

git show

Git responds with the last commit and a div containing all the changes

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git show
commit 30b68b19d2f952192faa25500af6fd4652f24b4c (HEAD -> master)
Author: Thiago Souto <thiago.souto@yahoo.com.br>
Date:   Fri Dec 20 10:22:03 2019 +1300

    Committing a README and
    a LICENSE files

diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..d79d88d
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,3 @@
+# LICENSE
+
+Thiago Souto
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d46a791
--- /dev/null
+++ b/README.md
@@ -0,0 +1,4 @@
+# Demo Project README
+
+
+Simple readme
\ No newline at end of file
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

To get out of the show command press "q"

# Express Commit - Combine Commands

To add and existing file being managed by git

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
LICENSE.md  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

To tell what files that git is tracking we use the git ls-files command

git ls-files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git ls-files
LICENSE.md
README.md
1
2
3
4

We can add a new file using the touch command


 















Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ touch new.file

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

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

no changes added to commit (use "git add" and/or "git commit -a")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

The new file is an Untracked file


The Express commit:

To add modified files to the staging area and directly proceed to committing we use git commit -a, we can also add the "m" to commit with a message, otherwise It will open the editor

TIP

the -a paramenter tells git to first add modified files to the git staging area and then directly proceed to commiting.

git commit -am

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -am "Updating README"
1
2

With git log we can see the two commits with the most recent at the top.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git log
commit 695a15ba3b8d3f6f94f0804e454597e6565844ec (HEAD -> master)
Author: Thiago Souto <thiago.souto@yahoo.com.br>
Date:   Fri Dec 20 10:52:47 2019 +1300

    Updating README

commit 30b68b19d2f952192faa25500af6fd4652f24b4c
Author: Thiago Souto <thiago.souto@yahoo.com.br>
Date:   Fri Dec 20 10:22:03 2019 +1300

    Committing a README and
    a LICENSE files
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# Backing Out Changes - Recovering from Mistakes

We can modify the readme.md file and add to the stage area

Then we can git reset HEAD readme.md to unstage the changes

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code readme.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add .

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git reset HEAD readme.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code readme.md
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

Now the the changes are unstaged but the modifications made on the file are still there.

To discard the changes we can

git checkout -- README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git checkout README.md
Updated 0 paths from the index
1
2
3

# History and Alias - Creating New Commands

git help log opens the manual page on the browser with lots of information


Although we can use some options like:


git log --oneline --graph --decorate --all

TIP

--oneline: Will provide a simplified commit entry providing a lighter information on a single line.

--graph: Will provide an asterisk based graph denoting the branching hierarchy.

--decorate: Which commits are a part of which branches and other labels within the git repository.

--all: Provides the history for all the branches.

We can look at this as a git history, although git doesn't have an official git history command.


To create a git history command we can use git alias to do so:


git config --global alias.hist "log --oneline --graph --decorate --all"

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git log --oneline
695a15b (HEAD -> master) Updating README
30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git log --oneline --graph --decorate --all
* 695a15b (HEAD -> master) Updating README
* 30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git config --global alias.hist "log --oneline --graph --decorate --all"

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git config --global --list
user.email=thiago.souto@yahoo.com.br
user.name=ThiagoSoutoGit
core.editor="C:\Users\Thiago Souto\AppData\Local\Programs\Microsoft VS Code\Code.exe" --wait
alias.hist=log --oneline --graph --decorate --all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

To use an alias:

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 695a15b (HEAD -> master) Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4

You can also use an alias with a continuation of the command:

git hist -- LICENSE.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist -- LICENSE.md
* 30b68b1 Committing a README and a LICENSE files
1
2
3

# Rename and Delete Files

Firs lets create, add and commit a file called example.txt.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code example.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        example.txt

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add example.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -m "adding example file"
[master d8d1327] adding example file
 1 file changed, 1 insertion(+)
 create mode 100644 example.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
example.txt  LICENSE.md  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean
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

Now lets change the name of the file using git commands

git mv example.txt demo.txt

With this command we are moving the file to its new name. Effectively renaming the file.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git mv example.txt demo.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
demo.txt  LICENSE.md  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        renamed:    example.txt -> demo.txt
1
2
3
4
5
6
7
8
9
10
11
12
13

As can be seeing at the git status this change is actually staged, indicated by changes to be committed.

To finish the task we have to commit.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -m "renaming example"
[master 10301c5] renaming example
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename example.txt => demo.txt (100%)
1
2
3
4
5

Removing the file using git then the deletion will be tracked.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git rm demo.txt
rm 'demo.txt'

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
LICENSE.md  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    demo.txt


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -m "deleting demo file"
[master 89ed01b] deleting demo file
 1 file changed, 1 deletion(-)
 delete mode 100644 demo.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

And after committing we are back into a clean working directory

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean
1
2
3
4

git hist

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 89ed01b (HEAD -> master) deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4
5
6
7

# Rename and Delete files outside Git

lets creat a file called myfile.txt using the tough command (this is a bash command) and lets rename the file LCENSE.md to LICENSE.txt using the mv command.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
LICENSE.md  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ touch myfile.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
LICENSE.md  myfile.txt  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ mv LICENSE.md LICENSE.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls -l
total 2
-rw-r--r-- 1 Thiago Souto 197121 25 Dec 20 10:11 LICENSE.txt
-rw-r--r-- 1 Thiago Souto 197121  0 Mar 31 19:13 myfile.txt
-rw-r--r-- 1 Thiago Souto 197121 84 Mar 31 17:40 README.md
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

lets see how git sees this:

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    LICENSE.md

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

no changes added to commit (use "git add" and/or "git commit -a")
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Lets update git about the changes with git add -u the -u stand for update.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add -u

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    LICENSE.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        LICENSE.txt
        myfile.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14

In order to include both addition and deletion we need to use git add -A, and that will cover all types of modifications possible on the current working directory and make those updates accordingly in the git index.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add -A

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        renamed:    LICENSE.md -> LICENSE.txt
        new file:   myfile.txt
1
2
3
4
5
6
7
8
9
10

Again, at this point this changes are only staged, now we can move to commit them.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -m "rename and add"
[master c73d387] rename and add
 2 files changed, 0 insertions(+), 0 deletions(-)
 rename LICENSE.md => LICENSE.txt (100%)
 create mode 100644 myfile.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* c73d387 (HEAD -> master) rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

To delete the myfile.txt we can use the rm bash command:

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls -l
total 2
-rw-r--r-- 1 Thiago Souto 197121 25 Dec 20 10:11 LICENSE.txt
-rw-r--r-- 1 Thiago Souto 197121  0 Mar 31 19:13 myfile.txt
-rw-r--r-- 1 Thiago Souto 197121 84 Mar 31 17:40 README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ rm myfile.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    myfile.txt

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add -u

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    myfile.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -m "remove myfile.txt"
[master 0f13cf4] remove myfile.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 myfile.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 0f13cf4 (HEAD -> master) remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

# Excluding Unwanted Files

lets suppose we have a log file that is created and we don't want this file:

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls -al
total 6
drwxr-xr-x 1 Thiago Souto 197121  0 Mar 31 19:23 ./
drwxr-xr-x 1 Thiago Souto 197121  0 Dec 20 09:19 ../
drwxr-xr-x 1 Thiago Souto 197121  0 Mar 31 19:25 .git/
-rw-r--r-- 1 Thiago Souto 197121 25 Dec 20 10:11 LICENSE.txt
-rw-r--r-- 1 Thiago Souto 197121 84 Mar 31 17:40 README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code application.log

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
application.log  LICENSE.txt  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        application.log

nothing added to commit but untracked files present (use "git add" to track)
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

Git give us nice facility for excluding files and folders that we don't want to in our git repository, its called a .git ignore file

The syntax for this file is simply one pattern or expression per line.

I could target that specific file with application.log or *.log for all log files.

code .gitignore

The gitignore file needs to be tracked on the git repository:

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code .gitignore

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add .gitignore

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -m "Adding ignore file"
[master 4ff06fe] Adding ignore file
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean
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

We are back in a clean directory and our application.log file has been excluded.

its still in our file system but its been ignored.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ ls
application.log  LICENSE.txt  README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 4ff06fe (HEAD -> master) Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4
5
6
7
8
9
10
11
12
13
14

lets just remove the application.log file with rm application.log

# 5️⃣ Advanced Beyond the basics

# Comparing differences

To see the deference between two commit points we use the git diff command.

We are now going to compare the position 695a15b with the special pointer HEAD.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 4ff06fe (HEAD -> master) Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git diff 695a15b HEAD
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bf0824e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.log
\ No newline at end of file
diff --git a/LICENSE.md b/LICENSE.txt
similarity index 100%
rename from LICENSE.md
rename to LICENSE.txt
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

We can also use the git difftool command, this will launch the diff tools installed

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git difftool 695a15b HEAD

This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
opendiff kdiff3 tkdiff xxdiff meld kompare gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare smerge emerge vimdiff

Viewing (1/2): '.gitignore'
Launch 'vimdiff' [Y/n]? y
1
2
3
4
5
6
7
8
9
10

WARNING

Install a decent diff tool in the future

We can see the difference between the last change, in this case I deleted the text Some more text from the file.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git diff
diff --git a/README.md b/README.md
index 9acc4de..69df753 100644
--- a/README.md
+++ b/README.md
@@ -7,5 +7,5 @@ Simple readme
 ## Adding more

-Some more text
+
1
2
3
4
5
6
7
8
9
10
11
12
13
14

WARNING

Get a look at the git diff command, its very powerful.

# Branching and Merge Types

Branch = Timeline of Commits, more accurately branches are the names or labels we give timelines in git.

We can create and delete branches without affecting timelines, all we are doing is creating or deleting labels of commit ranges in git.

We can create a new branch to do a bit of work and then rejoin the master branch by merging in any changes that occur on the new branch.



Fast Forward Merge:

  • Simplest case
  • Like Never Branched (Commits on Destination)
  • Can be Disabled




Automatic Merges: Happens when Git detects non-conflicting changes in the parent branch, Git is able to automatic resolve any conflicts.

  • Non-Conflicting merge detected
  • Preserves both Timelines
  • Merge Commit on destination


Manual Merge

  • Automatic Merge not possible
  • Conflicting Merge state (All merge conflicts must be resolved prior to moving forward with the commit)
  • Changes saved in merge commit (After all conflicts have been resolved those changes are saved on the merge commit)




# Special MArkers

HEAD

  • Points to last commit of current branch
  • Can be moved (Advanced)

# Branching

From last changes made we have a modified README.md file.

I could create another branch with the branch command and then separately switch to that branch or I can accomplish both by using the checkout command with a -b option.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git checkout -b updates
Switched to a new branch 'updates'

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ git branch
  master
* updates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

lets now change a file and add and commit from the new branch

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ git add .

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ git commit -m "Adding updates from branch"
[updates e889815] Adding updates from branch
 1 file changed, 2 insertions(+), 1 deletion(-)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ git status
On branch updates
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ git hist
* e889815 (HEAD -> updates) Adding updates from branch
* 4ff06fe (master) Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ git diff updates master
diff --git a/README.md b/README.md
index d853831..9acc4de 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,6 @@ Simple readme

 ## Adding more

-Modification from new brach
-

+Some more text
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
35
36
37
38
39
40
41
42

Now we are finish with all the updates on the updates branch. Now we are going to integrate the changes.

We need to first Switch to my parent branch, we can switch branches by using the checkout command.

git checkout master


And now we can merge with the command:


git merge updates


Because It is just a simple merge its able to do a fast-forward merge which means that we are going to pretend that you never really switched away from the master branch. So we are going to apply those commits directly from the master branch.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (updates)
$ git checkout master
Switched to branch 'master'

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* e889815 (updates) Adding updates from branch
* 4ff06fe (HEAD -> master) Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git merge updates
Updating 4ff06fe..e889815
Fast-forward
 README.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

 Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* e889815 (HEAD -> master, updates) Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
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

There are ways to disable the Fast-forward merge, but most of the time we would like this to happen.

We can now delete the brach that we are not using anymore

git branch -d updates

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git branch
* master
  updates

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git branch -d updates
Deleted branch updates (was e889815).

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git branch
* master

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* e889815 (HEAD -> master) Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

The history didn't go away, just the label updates did.

# Conflict resolution

Now we are going to cause a conflict and then resolve it.

git checkout -b 'very-bad' : creates a new branch and switches to it.

git brach -a : shows us all branches.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git checkout -b 'very-bad'
Switched to a new branch 'very-bad'

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (very-bad)
$ git branch -a
  master
* very-bad
1
2
3
4
5
6
7
8

Then we modify the README.md file, then use the express commit technique git commit -am "very bad update".

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (very-bad)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (very-bad)
$ git commit -am "very bad update"
[very-bad 0ee4900] very bad update
 1 file changed, 1 insertion(+), 1 deletion(-)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (very-bad)
$ git hist
* 0ee4900 (HEAD -> very-bad) very bad update
* e889815 (master) Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Now we can return back to master and I'm going to pretend that I'm another developer or that I forgot the changes I've made on the very bad branch.

So I modify the README.md and get back to terminal and express commit again with git commit -am "Causing issues again".

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -am "Causing issues again"
[master 283581d] Causing issues again
 1 file changed, 1 insertion(+), 1 deletion(-)
1
2
3
4
5
6
7

Now lets merge our very bad branch into our master branch












 

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git branch -a
* master
  very-bad

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git merge very-bad
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master|MERGING)
1
2
3
4
5
6
7
8
9
10
11
12

Now, as expected, the auto merging was unable to resolve the conflict. It doesn't know which version of our file we want. This places us in a merging state. Which is denoted by our command prompt with a branch name on one side and | MERGING

if we cat the file, which outputs the whole content of the file, the current version has these weird characters that denotes the parts of the file that are conflicted. Which is HEAD vs very-bad.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git branch -a
* master
  very-bad

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git merge very-bad
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master|MERGING)
$ cat README.md
# Demo Project README

Simple readme

## Adding more

<<<<<<< HEAD
I hope this is not much of a problem.
=======
This is bound to cause problem
>>>>>>> very-bad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

We can Install P4Merge tool



Now we can configure P4Mege tool to be accessible from any command prompt. By adding to the system path. After copying the file path C:\Program Files\Perforce we go to this PC properties -> Advanced system settings -> Environmental Variables -> System variables -> Path -> Edit -> New and paste C:\Program Files\Perforce


Since this is a very simple case we could manually modify this file. We have a merged tool configured, so lets use it.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master|MERGING)
$ git mergetool

This message is displayed because 'merge.tool' is not configured.
See 'git mergetool --tool-help' or 'git help config' for more details.
'git mergetool' will now attempt to use one of the following tools:
opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc codecompare smerge emerge vimdiff
Merging:
README.md

Normal merge conflict for 'README.md':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (p4merge):
1
2
3
4
5
6
7
8
9
10
11
12
13
14


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master|MERGING)
$ git commit -m "Resolving conflict"
[master 0163d02] Resolving conflict


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
*   0163d02 (HEAD -> master) Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# Tagging

Now we have been working for quite some time on the repository and we want to mark this with a tag. Tags are just labels that you can put on any arbitrary commit point.

There are light weight tags with git tag mytag, which has no associated information with it.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git tag mytag

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 3db6c68 (HEAD -> master, tag: mytag) Ignore file
*   0163d02 Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git tag -d mytag
Deleted tag 'mytag' (was 3db6c68)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 3db6c68 (HEAD -> master) Ignore file
*   0163d02 Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
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
35
36
37
38
39
40
41
42

And also annotated tags which has extra information associated with the tag.


git tag -a v1.0 -m "Release 1.0"

-a for annotated

And we can see the information of the tag by using git show v1.0

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git tag -a v1.0 -m "Release 1.0"

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git tag --list
v1.0

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 3db6c68 (HEAD -> master, tag: v1.0) Ignore file
*   0163d02 Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git show v1.0
tag v1.0
Tagger: ThiagoSoutoGit <thiago.souto@yahoo.com.br>
Date:   Wed Apr 1 11:33:24 2020 +1300

Release 1.0

commit 3db6c687aaabfe8e1b3bd5ed4042c91b3467f010 (HEAD -> master, tag: v1.0)
Author: ThiagoSoutoGit <thiago.souto@yahoo.com.br>
Date:   Wed Apr 1 11:08:25 2020 +1300

    Ignore file

diff --git a/gitignore b/gitignore
new file mode 100644
index 0000000..38155c7
--- /dev/null
+++ b/gitignore
@@ -0,0 +1,2 @@
+*.orig
+*.log
\ No newline at end of file
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48

# Saving Work in Progress with Stashing

We are now at the master branch on a clean working directory. And we are going to edit the README.md file.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

What if we decide that we shouldn't be doing that right now, and you should've started it on a branch or we should change context and work in something else right now.

We can do that by using git stashing ability.

git stash

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git stash
Saved working directory and index state WIP on master: 3db6c68 Ignore file
1
2
3

git stash list shows us our stashes, in this case a Work In Progress at masters, It shows us the last commit and the associated commit message.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git stash
Saved working directory and index state WIP on master: 3db6c68 Ignore file

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git stash list
stash@{0}: WIP on master: 3db6c68 Ignore file
1
2
3
4
5
6
7

Now lets change the LICENSE.md file.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code LICENSE.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -am "updating license file"
On branch master
Untracked files:
        LICENSE.md

nothing added to commit but untracked files present

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add LICENSE.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -am "updating license file"
[master 3f1321a] updating license file
 1 file changed, 3 insertions(+)
 create mode 100644 LICENSE.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Now lets apply our stash

git stash pop

That will do two actions: an apply and a drop. The stash apply will apply whatever the stash is, the last stash, in this case we put the changes back in the README.md file, then after that It dropped that stash that was applied.

with a git stash list I have no results and the README.md file was updated as it was prior to the stash.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git stash list

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git commit -am "updating readme again"
[master 968865b] updating readme again
 1 file changed, 1 insertion(+), 1 deletion(-)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# Time Travel with Reset and Reflog

lets modify the README.md file two times, to have modifications at the staging area and in the working file.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git add .

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 968865b (HEAD -> master) updating readme again
* 3f1321a updating license file
* 3db6c68 (tag: v1.0) Ignore file
*   0163d02 Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

Now lets reset, there is the soft reset, there is the default which is called mixed and there is hard. The soft reset is the list destructive of them all, basically all it does is changing where HEAD is pointing.

git reset 3db6c68 --soft

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git reset 3db6c68 --soft

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 3db6c68 (HEAD -> master, tag: v1.0) Ignore file
*   0163d02 Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

After doing a git status we can see that we still have the files at the staging area and at the working directory, because the soft reset only changed the HEAD position. Effectively we can backup our changes, make minor modifications to it and then commit where HEAD is currently pointing.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   LICENSE.md
        modified:   README.md

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md
1
2
3
4
5
6
7
8
9
10
11
12

lets do a mixed now:

git reset 4ff06fe --mixed

when we do a git status we have several files that were unstaged and put on our working directory. there is nothing in our staging area.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git reset 4ff06fe
Unstaged changes after reset:
M       README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

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

no changes added to commit (use "git add" and/or "git commit -a")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Now lets try the hard one:

git reset 695a15b --hard

if we do a git status we see that our working directory is now clean, which means that any changes that were pending have been wiped out, along with anything that were at the staging area.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git reset 695a15b --hard
HEAD is now at 695a15b Updating README

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 3db6c68 (tag: v1.0) Ignore file
*   0163d02 Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b (HEAD -> master) Updating README
* 30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        gitignore

nothing added to commit but untracked files present (use "git add" to track)
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

if we do a git log --oneline, we can see we only have two commits being listed

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git log --oneline
695a15b (HEAD -> master) Updating README
30b68b1 Committing a README and a LICENSE files
1
2
3
4

We can use the command git reflog, since it shows all the actions taken we can move back to any commit id.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git reflog
695a15b (HEAD -> master) HEAD@{0}: reset: moving to 695a15b
4ff06fe HEAD@{1}: reset: moving to 4ff06fe
3db6c68 (tag: v1.0) HEAD@{2}: reset: moving to 3db6c68
968865b HEAD@{3}: commit: updating readme again
3f1321a HEAD@{4}: commit: updating license file
3db6c68 (tag: v1.0) HEAD@{5}: reset: moving to HEAD
3db6c68 (tag: v1.0) HEAD@{6}: commit: Ignore file
0163d02 HEAD@{7}: commit (merge): Resolving conflict
283581d HEAD@{8}: commit: Causing issues again
e889815 HEAD@{9}: checkout: moving from very-bad to master
0ee4900 (very-bad) HEAD@{10}: commit: very bad update
e889815 HEAD@{11}: checkout: moving from master to very-bad
e889815 HEAD@{12}: merge updates: Fast-forward
4ff06fe HEAD@{13}: checkout: moving from updates to master
e889815 HEAD@{14}: commit: Adding updates from branch
4ff06fe HEAD@{15}: checkout: moving from master to updates
4ff06fe HEAD@{16}: commit: Adding ignore file
0f13cf4 HEAD@{17}: commit: remove myfile.txt
c73d387 HEAD@{18}: commit: rename and add
89ed01b HEAD@{19}: commit: deleting demo file
10301c5 HEAD@{20}: commit: renaming example
d8d1327 HEAD@{21}: commit: adding example file
695a15b (HEAD -> master) HEAD@{22}: commit: Updating README
30b68b1 HEAD@{23}: commit (initial): Committing a README and
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

Lets move to 968865b

git reset --hard 968865b

and we can see our history back again

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git reset --hard 968865b
HEAD is now at 968865b updating readme again

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git log --oneline
968865b (HEAD -> master) updating readme again
3f1321a updating license file
3db6c68 (tag: v1.0) Ignore file
0163d02 Resolving conflict
283581d Causing issues again
0ee4900 (very-bad) very bad update
e889815 Adding updates from branch
4ff06fe Adding ignore file
0f13cf4 remove myfile.txt
c73d387 rename and add
89ed01b deleting demo file
10301c5 renaming example
d8d1327 adding example file
695a15b Updating README
30b68b1 Committing a README and a LICENSE files

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git hist
* 968865b (HEAD -> master) updating readme again
* 3f1321a updating license file
* 3db6c68 (tag: v1.0) Ignore file
*   0163d02 Resolving conflict
|\
| * 0ee4900 (very-bad) very bad update
* | 283581d Causing issues again
|/
* e889815 Adding updates from branch
* 4ff06fe Adding ignore file
* 0f13cf4 remove myfile.txt
* c73d387 rename and add
* 89ed01b deleting demo file
* 10301c5 renaming example
* d8d1327 adding example file
* 695a15b Updating README
* 30b68b1 Committing a README and a LICENSE files
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
35
36
37
38
39
40
41

# 6️⃣ GitHub

# Creating a new Repo

Click on New repository at your account on GitHub, fill the Repository name, Description check public (private is paid) and do not check initialize this repository with a README. Then click the create repository button.

# Linking a local repository to a GitHub repository

On the folder to be pushed to GitHub:

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/BVQR_TECHNICAL_MANUAL
$ git status
fatal: not a git repository (or any of the parent directories): .git

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/BVQR_TECHNICAL_MANUAL
$ git init .
Initialized empty Git repository in C:/Users/Thiago Souto/Desktop/VUEPRESS/BVQR_TECHNICAL_MANUAL/.git/

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/BVQR_TECHNICAL_MANUAL (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        docs/
        node_modules/
        package-lock.json
        package.json
        yarn.lock

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

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/BVQR_TECHNICAL_MANUAL (master)
$ git remote -v

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/BVQR_TECHNICAL_MANUAL (master)
$ git remote add origin https://github.com/ThiagoSoutoGit/BVQR_Manual.git

Thiago Souto@MSI MINGW64 ~/Desktop/VUEPRESS/BVQR_TECHNICAL_MANUAL (master)
$ git remote -v
origin  https://github.com/ThiagoSoutoGit/BVQR_Manual.git (fetch)
origin  https://github.com/ThiagoSoutoGit/BVQR_Manual.git (push)
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 remote -v, returns nothing because we don't have any remote set.

git remote add origin https://github.com/ThiagoSoutoGit/Demo.git, this command starts with git remote and a sub-command add. The add sub-command takes 2 parameters, the name of the remote reference we want to create, in this case origin, and the full url to the remote repository. We can use any name instead of origin, but by convention the first and primary remote repository is named origin.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git remote -v

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git remote add origin https://github.com/ThiagoSoutoGit/Demo.git

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git remote -v
origin  https://github.com/ThiagoSoutoGit/Demo.git (fetch)
origin  https://github.com/ThiagoSoutoGit/Demo.git (push)
1
2
3
4
5
6
7
8
9
10

# Push Changes to GitHub - Upload Local Repo

git push -u origin master --tags

git push -u- setup a tracking branch relationship between the master branch on the local repository and the master branch on the remote repository

origin- name of the remote repository

master- name of the branch we are going to push

--tags - send all the tags that we have currently on our repository up to git hub

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/demo (master)
$ git push -u origin master --tags
Enumerating objects: 41, done.
Counting objects: 100% (41/41), done.
Delta compression using up to 12 threads
Compressing objects: 100% (34/34), done.
Writing objects: 100% (41/41), 3.89 KiB | 664.00 KiB/s, done.
Total 41 (delta 10), reused 0 (delta 0)
remote: Resolving deltas: 100% (10/10), done.
To https://github.com/ThiagoSoutoGit/Demo.git
 * [new branch]      master -> master
 * [new tag]         v1.0 -> v1.0
Branch 'master' set up to track remote branch 'master' from 'origin'.
1
2
3
4
5
6
7
8
9
10
11
12
13

# Pushing to BVQR Manual

yarn docs:build

git add .

git commit -m "Finished Manual commit"

npm run push
1
2
3
4
5
6
7

Password: ********************

"push": "scp -r docs/.vuepress/dist/* frontend@223.165.66.36:~container/application/public/manual/"

# Verifying our Changes on GitHub

Just go to the repository at GitHub and check the tags and everything.

Remember to refresh the page to see the changes.

# 7️⃣ SSH Authentication

Create a folder .ssh and execute this ssh-keygen -t rsa -C "thiago.souto@yahoo.com.br"

-t: type rsa: -C: common name

After entering the new Key at your profile settings at GitHub verify by using this command: ssh -T git@github.com

Thiago Souto@MSI MINGW64 ~/desktop/vuepress/programming/.ssh
$ ssh -T git@github.com
Hi ThiagoSoutoGit! You've successfully authenticated, but GitHub does not provide shell access.
1
2
3

# 8️⃣ GitHub Repository

Now we are going to create a new repository called my-website, Public, with a README file, a gitignore towards Node files and an Apache License 2.0.



With this instead of going to a page with instructions GitHub goes to the repository page. That's why we initialize our repository with a hand full of files. So github created a initial master branch with a initial commit which has the setup files.



# Create a Local Copy with Clone

We can clone normally via Https or via SSH. Here we are going to cline via SSH.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ git clone git@github.com:ThiagoSoutoGit/my-website.git
Cloning into 'my-website'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
Receiving objects: 100% (5/5), 5.30 KiB | 5.30 MiB/s, done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ ls -l
total 8
drwxr-xr-x 1 Thiago Souto 197121 0 Apr  1 16:37 demo/
drwxr-xr-x 1 Thiago Souto 197121 0 Apr  3 09:02 my-website/

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ cd my-website/

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/my-website (master)
$ ls -al
total 25
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 09:02 ./
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 09:02 ../
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 09:02 .git/
-rw-r--r-- 1 Thiago Souto 197121  1714 Apr  3 09:02 .gitignore
-rw-r--r-- 1 Thiago Souto 197121 11558 Apr  3 09:02 LICENSE
-rw-r--r-- 1 Thiago Souto 197121    12 Apr  3 09:02 README.md
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

When we clone Git sets origin to be our remote repository.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/my-website (master)
$ git remote -v
origin  git@github.com:ThiagoSoutoGit/my-website.git (fetch)
origin  git@github.com:ThiagoSoutoGit/my-website.git (push)
1
2
3
4

We can also clone to a folder which we choose the name with

git clone git@github.com:ThiagoSoutoGit/my-website.git website

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ rm -rf my-website

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ ls -l
total 4
drwxr-xr-x 1 Thiago Souto 197121 0 Apr  1 16:37 demo/

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ git clone git@github.com:ThiagoSoutoGit/my-website.git website
Cloning into 'website'...
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), 5.30 KiB | 1.06 MiB/s, done.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# Seeding the Repository with Sample Content

Now we are going to initialize our repository with a basic website.

http://www.initializr.com/



lets use a command to copy all the files.

cp -R ~/Downloads/initializr/* .

-R : for Recursive

~/ : User's home directory

  • : Everything under the folder

. : Destination, current folder


Note that I had to unzip the folder first.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ ls
demo/  website/

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects
$ cd website

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ cp -R ~/Downloads/initializr/* .
cp: cannot stat '/c/Users/Thiago Souto/Downloads/initializr/*': No such file or directory

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ cp -R ~/Downloads/initializr/* .

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ ls -al
total 58
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 ./
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 09:06 ../
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 09:06 .git/
-rw-r--r-- 1 Thiago Souto 197121  1714 Apr  3 09:06 .gitignore
-rw-r--r-- 1 Thiago Souto 197121  3959 Apr  3 10:22 apple-touch-icon.png
-rw-r--r-- 1 Thiago Souto 197121   416 Apr  3 10:22 browserconfig.xml
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 css/
-rw-r--r-- 1 Thiago Souto 197121   766 Apr  3 10:22 favicon.ico
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 fonts/
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 img/
-rw-r--r-- 1 Thiago Souto 197121  5283 Apr  3 10:22 index.html
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 js/
-rw-r--r-- 1 Thiago Souto 197121 11558 Apr  3 09:06 LICENSE
-rw-r--r-- 1 Thiago Souto 197121    12 Apr  3 09:06 README.md
-rw-r--r-- 1 Thiago Souto 197121  3482 Apr  3 10:22 tile.png
-rw-r--r-- 1 Thiago Souto 197121  1854 Apr  3 10:22 tile-wide.png
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

Now lets add, commit and push all the new files to the git

git add .

git commit -m "Adding initial website files"

git push origin master

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        apple-touch-icon.png
        browserconfig.xml
        css/
        favicon.ico
        fonts/
        index.html
        js/
        tile-wide.png
        tile.png

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git add .
warning: LF will be replaced by CRLF in browserconfig.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in css/bootstrap-theme.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in css/bootstrap-theme.min.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in css/bootstrap.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in css/bootstrap.min.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in css/main.css.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in fonts/glyphicons-halflings-regular.svg.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in index.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/main.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/vendor/bootstrap.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/vendor/bootstrap.min.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/vendor/jquery-1.11.2.min.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/vendor/modernizr-2.8.3-respond-1.4.2.min.js.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in js/vendor/npm.js.
The file will have its original line endings in your working directory

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   apple-touch-icon.png
        new file:   browserconfig.xml
        new file:   css/bootstrap-theme.css
        new file:   css/bootstrap-theme.css.map
        new file:   css/bootstrap-theme.min.css
        new file:   css/bootstrap.css
        new file:   css/bootstrap.css.map
        new file:   css/bootstrap.min.css
        new file:   css/main.css
        new file:   favicon.ico
        new file:   fonts/glyphicons-halflings-regular.eot
        new file:   fonts/glyphicons-halflings-regular.svg
        new file:   fonts/glyphicons-halflings-regular.ttf
        new file:   fonts/glyphicons-halflings-regular.woff
        new file:   index.html
        new file:   js/main.js
        new file:   js/vendor/bootstrap.js
        new file:   js/vendor/bootstrap.min.js
        new file:   js/vendor/jquery-1.11.2.min.js
        new file:   js/vendor/modernizr-2.8.3-respond-1.4.2.min.js
        new file:   js/vendor/npm.js
        new file:   tile-wide.png
        new file:   tile.png


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git commit -m "Adding initial website files"
[master 64a922f] Adding initial website files
 23 files changed, 9539 insertions(+)
 create mode 100644 apple-touch-icon.png
 create mode 100644 browserconfig.xml
 create mode 100644 css/bootstrap-theme.css
 create mode 100644 css/bootstrap-theme.css.map
 create mode 100644 css/bootstrap-theme.min.css
 create mode 100644 css/bootstrap.css
 create mode 100644 css/bootstrap.css.map
 create mode 100644 css/bootstrap.min.css
 create mode 100644 css/main.css
 create mode 100644 favicon.ico
 create mode 100644 fonts/glyphicons-halflings-regular.eot
 create mode 100644 fonts/glyphicons-halflings-regular.svg
 create mode 100644 fonts/glyphicons-halflings-regular.ttf
 create mode 100644 fonts/glyphicons-halflings-regular.woff
 create mode 100644 index.html
 create mode 100644 js/main.js
 create mode 100644 js/vendor/bootstrap.js
 create mode 100644 js/vendor/bootstrap.min.js
 create mode 100644 js/vendor/jquery-1.11.2.min.js
 create mode 100644 js/vendor/modernizr-2.8.3-respond-1.4.2.min.js
 create mode 100644 js/vendor/npm.js
 create mode 100644 tile-wide.png
 create mode 100644 tile.png

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push origin master
Enumerating objects: 30, done.
Counting objects: 100% (30/30), done.
Delta compression using up to 12 threads
Compressing objects: 100% (28/28), done.
Writing objects: 100% (29/29), 273.94 KiB | 1.42 MiB/s, done.
Total 29 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), done.
To github.com:ThiagoSoutoGit/my-website.git
   a48b427..64a922f  master -> master
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121


# Publish back to GitHub

With git push it only sends the current tracking branch up to your remote repository.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push
Everything up-to-date
1
2
3

If you getting a long message from git because you are using a later version execute the command below, to get rid of the message.

git config --global push.default simple

# Fetch and Pull

We are just going to make a little change directly on the repository at GitHub.



Now lets change the README.md file locally on bash and use express commit to commit the changes.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git commit -am "Updating README"
[master c0d0887] Updating README
 1 file changed, 3 insertions(+), 1 deletion(-)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Now as you can see git tells us that we are ahead of 'origin/master' by 1 commit. It will reject our push and tell us to fetch first.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push
To github.com:ThiagoSoutoGit/my-website.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:ThiagoSoutoGit/my-website.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
1
2
3
4
5
6
7
8
9
10

One thing to keep in mind is although we are using the term pull a pull is in fact two commands in one, a fetch and also a merge. Git will first fetch all the updates from the remote repository and then It will merge those changes into our current repository.


Of course there is an opportunity for this to fail in a form of a merge conflict, but often times the merge goes automatically or as a fast forward.


If we are not sure, we can do a fetch or a pull in this scenario. If we did the pull, we would automatically integrate any changes that are out on GitHub. However, that can be a destructive command. If you have changes that are not compatible with what's currently on GitHub.

So, one way to alleviate that is just to do a "fetch"; fetches are non-destructive.

git fetch; Git will now go out to our remote repository and update all of its local information based on what's changed out on GitHub.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
Unpacking objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
From github.com:ThiagoSoutoGit/my-website
   64a922f..abe46aa  master     -> origin/master

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Now, when we do a "git status", Git tells us that 'origin/master' has diverged from our local master branch that we have one commit that's different on each side.

And, it recommends that we use "git pull" to automatically merge our remote branch. Technically, we could do this with the "git merge" command as well, but just like the advice given, I often find that just doing a git pull is a lot simpler.

It will pop the commit message, and if you are happy just close.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git pull
hint: Waiting for your editor to close the file...
Merge made by the 'recursive' strategy.
 index.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
1
2
3
4
5
6

We just merged down everything from GitHub.

GitHub is still unaware of our changes, so we need to push up what we have.

Type git push. Great, now that we have pulled down all our changes

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push
Enumerating objects: 9, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 12 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 596 bytes | 298.00 KiB/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:ThiagoSoutoGit/my-website.git
   abe46aa..b9ce76c  master -> master
1
2
3
4
5
6
7
8
9
10
11

There are no conflicts between GitHub and our local repo.

So, when we do a push, it goes in just fine. Doing a pull, or a fetch, prior to any pushes is a best practice, and a necessity if you are sharing your repository with others.


Alright, lets go very our changes on GitHub.

If I reload, we can see the last commit message is our merge commit message that we just entered in with our text editor.

And, you can see the updates to the Readme file the index was already updated on GitHub.

# Updating Repositories and Remote References

We have change the name of the repository on the settings page.

As a consequence to that, any clones of this repository we'll need to update the references so they will continue to work.

We will have to update the remote with the command:

git remote set-url origin git@github.com:ThiagoSoutoGit/website.git

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git remote -v
origin  git@github.com:ThiagoSoutoGit/my-website.git (fetch)
origin  git@github.com:ThiagoSoutoGit/my-website.git (push)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git remote set-url origin git@github.com:ThiagoSoutoGit/website.git

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git remote -v
origin  git@github.com:ThiagoSoutoGit/website.git (fetch)
origin  git@github.com:ThiagoSoutoGit/website.git (push)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git remote show origin
* remote origin
  Fetch URL: git@github.com:ThiagoSoutoGit/website.git
  Push  URL: git@github.com:ThiagoSoutoGit/website.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
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

# Creating files in github

To create a new file should be on a featured branch as a good practice.



I'm going to click on "Propose new file". Going this way around,

We are effectively creating a pull request back into our master branch.

In addition to the commit message we had before, we also have a pull request commit message and a comment to go along with it.



Then I accept my pull request



After confirming I have the opportunity to delete the branch.


We can also create files directly on the master branch and renaming and deleting files.

# Synchronizing our Changes with our Local Repository

Just do a git fetch and a git pull.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ pwd
/c/Users/Thiago Souto/Desktop/GitProjects/website

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From github.com:ThiagoSoutoGit/website
   b9ce76c..64b9aeb  master     -> origin/master

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git pull
Updating b9ce76c..64b9aeb
Fast-forward
 Lipsum.txt | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 Lipsum.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ ls -al
total 59
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 12:12 ./
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 09:06 ../
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 12:12 .git/
-rw-r--r-- 1 Thiago Souto 197121  1714 Apr  3 09:06 .gitignore
-rw-r--r-- 1 Thiago Souto 197121  3959 Apr  3 10:22 apple-touch-icon.png
-rw-r--r-- 1 Thiago Souto 197121   416 Apr  3 10:22 browserconfig.xml
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 css/
-rw-r--r-- 1 Thiago Souto 197121   766 Apr  3 10:22 favicon.ico
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 fonts/
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 img/
-rw-r--r-- 1 Thiago Souto 197121  5399 Apr  3 11:00 index.html
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 js/
-rw-r--r-- 1 Thiago Souto 197121 11558 Apr  3 09:06 LICENSE
-rw-r--r-- 1 Thiago Souto 197121   603 Apr  3 12:12 Lipsum.txt
-rw-r--r-- 1 Thiago Souto 197121    49 Apr  3 10:43 README.md
-rw-r--r-- 1 Thiago Souto 197121  3482 Apr  3 10:22 tile.png
-rw-r--r-- 1 Thiago Souto 197121  1854 Apr  3 10:22 tile-wide.png
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

# Commit Details

We can go to the commits details on the repositories, as seen below.



We can also comment.



# GitHub Time Travel Reviwing Your Repository as of a Particular Commit

In the commit history, the angle brackets on the right side of the commits means the I can browse the repository at that point in time.



# Using Commit IDs with the Local Repository

We can copy the "full SHA" commit ID from the GitHub and go back in time from bash.



Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git show 83be7149f125b869b0e84fbf100111246b4f02f0
commit 83be7149f125b869b0e84fbf100111246b4f02f0
Author: Thiago Souto <53646778+ThiagoSoutoGit@users.noreply.github.com>
Date:   Fri Apr 3 12:02:39 2020 +1300

    Create new file -- filler text

diff --git a/Lipsum.txt b/Lipsum.txt
new file mode 100644
index 0000000..8911f7a
--- /dev/null
+++ b/Lipsum.txt
@@ -0,0 +1,3 @@
+#What is Lorem Ipsum?
+
+* Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularized in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 9️⃣ Git Repository Branches

In this field that we have above the listing of branches, is a combination search field and create branch field. If you type something in that matches an existing branch, then it will find that branch, and switch to it; however, if it does not find a match, GitHub assumes that you want to create the branch.

So, when you press enter, it will create that branch.


So, lets do that now; I'm going to create a branch called "example". Since we don't have any branches named example, GitHub will assume that we want to create a branch, which we do. It also indicates that we will be creating this example branch directly off of master.



lets now edit the README.md file



# Local Branches

lets now create from the terminal a new branch. With this command we are going to create a new branch and move to it.

git checkout -b remove-ipsum

-b : create the branch locally

remove-ipsum : name of the branch

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git checkout -b remove-ipsum
Switched to a new branch 'remove-ipsum'

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ ls -l
total 47
-rw-r--r-- 1 Thiago Souto 197121  3959 Apr  3 10:22 apple-touch-icon.png
-rw-r--r-- 1 Thiago Souto 197121   416 Apr  3 10:22 browserconfig.xml
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 css/
-rw-r--r-- 1 Thiago Souto 197121   766 Apr  3 10:22 favicon.ico
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 fonts/
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 img/
-rw-r--r-- 1 Thiago Souto 197121  5399 Apr  3 11:00 index.html
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 js/
-rw-r--r-- 1 Thiago Souto 197121 11558 Apr  3 09:06 LICENSE
-rw-r--r-- 1 Thiago Souto 197121   603 Apr  3 12:12 Lipsum.txt
-rw-r--r-- 1 Thiago Souto 197121    49 Apr  3 10:43 README.md
-rw-r--r-- 1 Thiago Souto 197121  3482 Apr  3 10:22 tile.png
-rw-r--r-- 1 Thiago Souto 197121  1854 Apr  3 10:22 tile-wide.png

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ git rm Lipsum.txt
rm 'Lipsum.txt'

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ git status
On branch remove-ipsum
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    Lipsum.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ git commit -m "Removing Ipsum file"
[remove-ipsum 3a3a669] Removing Ipsum file
 1 file changed, 3 deletions(-)
 delete mode 100644 Lipsum.txt

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ ls -l
total 46
-rw-r--r-- 1 Thiago Souto 197121  3959 Apr  3 10:22 apple-touch-icon.png
-rw-r--r-- 1 Thiago Souto 197121   416 Apr  3 10:22 browserconfig.xml
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 css/
-rw-r--r-- 1 Thiago Souto 197121   766 Apr  3 10:22 favicon.ico
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 fonts/
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 img/
-rw-r--r-- 1 Thiago Souto 197121  5399 Apr  3 11:00 index.html
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 js/
-rw-r--r-- 1 Thiago Souto 197121 11558 Apr  3 09:06 LICENSE
-rw-r--r-- 1 Thiago Souto 197121    49 Apr  3 10:43 README.md
-rw-r--r-- 1 Thiago Souto 197121  3482 Apr  3 10:22 tile.png
-rw-r--r-- 1 Thiago Souto 197121  1854 Apr  3 10:22 tile-wide.png

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ git status
On branch remove-ipsum
nothing to commit, working tree clean
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

The remove-ipsum branch is not on GitHub, so lets push that up.

git push -u origin remove-ipsum

-u : sets up the tracking relationship origin : name of the remote remove-lipsum: brach we want to push up

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ git push -u origin remove-ipsum
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 240 bytes | 240.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote:
remote: Create a pull request for 'remove-ipsum' on GitHub by visiting:
remote:      https://github.com/ThiagoSoutoGit/website/pull/new/remove-ipsum
remote:
To github.com:ThiagoSoutoGit/website.git
 * [new branch]      remove-ipsum -> remove-ipsum
Branch 'remove-ipsum' set up to track remote branch 'remove-ipsum' from 'origin'.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# Comparing and Pull Requests

We can access the branches and click the New pull request button.



By default, if there are no forks involved, which we will cover later, GitHub will automatically do a compare and prepare for a pull request based on the default branch, which in this case is master.



We can also use emojis at the comments



Then we can just merge pull request and confirm.

After merge we have the opportunity safely delete the branch using a dedicated button.

# Merging locally

We are going to show you an alternative way to integrate your changes into the master branch, this time from the local side.

I'm currently on GitHub, logged in, and on the website GitHub repository. I'm currently on the master branch, and GitHub is letting us know that we have this "remove-ipsum" branch just laying around.

Since its a recent branch, the GitHub interface thinks we might want to do a pull request, and most of the time that would probably be true; however, I'm going to integrate the changes that I have on the local side.

So, lets hop over to our terminal.

Back on our system, I'm currently in the website Git repository, and I'm on the "remove-ipsum" branch. Since we just pushed everything up, the branch is in a clean working directory state and it is up-to-date with 'origin/remove-ipsum', which is a tracking branch.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ git status
On branch remove-ipsum
Your branch is up to date with 'origin/remove-ipsum'.

nothing to commit, working tree clean
1
2
3
4
5
6

In order to integrate our changes into master, we need to change back to the master branch. --> 00:01:02.733 Switching branches in Git, we need to use the "checkout" command: "git checkout master".

Once you've switched to the master branch, since we haven't fetched anything recently, our local repo doesn't realize that its actually out of date. So, I know that the changes should be fairly benign, so I'm just going to do a "git pull".

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (remove-ipsum)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git pull
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), done.
From github.com:ThiagoSoutoGit/website
   64b9aeb..592b1de  master     -> origin/master
Updating 64b9aeb..592b1de
Fast-forward
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Great, now we've integrated all the changes that have changed on master from our GitHub repository. So, now we're ready to integrate our changes that we have on our local "remove-ipsum" branch. Type "git merge"; space; and then the branch to merge in, which is "remove-ipsum".

git merge remove-ipsum

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git merge remove-ipsum
Removing Lipsum.txt
hint: Waiting for your editor to close the file...
Merge made by the 'recursive' strategy.
 Lipsum.txt | 3 ---
 1 file changed, 3 deletions(-)
 delete mode 100644 Lipsum.txt
1
2
3
4
5
6
7
8

Since this is not a fast-forward merge, but it is still an automatic merge, I'm being prompted for my merge message, with a default message being provided. I'm going to save and close, and whatever I typed in my default editor will be used as the merge commits message. Using "git status", we see that our local master is "ahead of 'origin/master' by 2 commits", which would be the commits for the actual deletion of the "lipsum.txt" file and then our merge commit that we had when we did the merge back into master.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
1
2
3
4
5
6
7

So now, lets synchronize our local changes back up to GitHub. with git push

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 276 bytes | 276.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:ThiagoSoutoGit/website.git
   592b1de..4337f44  master -> master

   Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Now lets delete the branch from GitHub page.

However, we're not done yet; lets go back to our terminal, and we have two things going on. If I do a git branch -a, I can see that I have a "remove-ipsum" branch still laying around.

That's the local branch that we started out with before we pushed it up to GitHub and then later merged it back into master.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -a
* master
  remove-ipsum
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/remove-ipsum
1
2
3
4
5
6
7

We also still have that branch on GitHub, or at least the reference to it; that's under "remotes/origin/", branch name. So, lets fix both of those things; first thing I'm going to do is delete our branch. git branch -d for delete; space; and then our branch name, which is "remove-ipsum".

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -d remove-ipsum
Deleted branch remove-ipsum (was 3a3a669).
1
2
3

Great, we have deleted that branch. Now, Git would have warned us if we had not already integrated those changes into master, so that's an important step.

Now, if I do a git branch -a, we are left with a master branch locally

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/remove-ipsum
1
2
3
4
5
6

But we still have the "remove-ipsum" branch referenced on origin; however, we know that that branch doesn't exist on GitHub, its just a stale reference. So, we need to update those stale references.

And one way to do that is with the git fetch command.

Type "git fetch"; space; and then "-p", the "-p" is the prune option, which means its going to look for any dead branches and remove those references.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git fetch -p
From github.com:ThiagoSoutoGit/website
 - [deleted]         (none)     -> origin/remove-ipsum

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
1
2
3
4
5
6
7
8
9
10

Now we only have master on the remote side, and then, of course, our special pointer called "HEAD". Either way, the "remove-ipsum" branch is no longer locally referenced or pointing to our remote.

# Locally Switch to a branch on GitHub

In addition to starting with a branch on your local repository and then pushing it up to GitHub, you could also work from the other direction, which is to create a branch on GitHub, then check out that particular branch on your local system.


After creating a new branch called update-readme and editing the README file, we can check on owr system and fetch the changes with git fetch

Typing "git fetch" will update our remote, which would include any new branches that it might be aware of. And, at the end, you can see that we have a new branch "update-readme". Now our references show an "update-readme" on origin. There are several ways that I can link a local branch


Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
Unpacking objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
From github.com:ThiagoSoutoGit/website
 * [new branch]      update-readme -> origin/update-readme

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/update-readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Type "git checkout"; space; and then the name of the branch that you want to checkout, even though this branch isn't local. Now, this only works if you have a single remote repository;

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git checkout update-readme
Switched to a new branch 'update-readme'
Branch 'update-readme' set up to track remote branch 'update-readme' from 'origin'.
1
2
3
4

The reason why this works, is that Git will figure out what you mean by the name of the branch that you're specifying. its first going to look for a local branch named "update-readme", and when it fails to find it, it will look for the name of that branch among the remotes. As long as the branch name is unique among your remotes, it will find it and be able to check out that branch; however, if you have a scenario where you have multiple remotes pointing to similar repositories, where there are overlaps with the names of the branches, Git is not going to be able to figure that out, and thus you'll need to take another approach to link a local branch with the specific branch on your remote that you want to link.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (update-readme)
$ git branch -a
  master
* update-readme
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/update-readme
1
2
3
4
5
6
7

Now lets update the readme locally

Alright, so now we're ready to push up our changes. And, since this is a tracking branch, we don't need to specify the remote reference or the branch; we're going to assume the tracking relationship, wherever that happens to be pointing with our current branch. git push, and Git figures out I mean push to the corresponding "update-readme" branch on GitHub.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (update-readme)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (update-readme)
$ git commit -am "More tweakes to README"
[update-readme 1708ed3] More tweakes to README
 1 file changed, 2 insertions(+), 2 deletions(-)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (update-readme)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 324 bytes | 162.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:ThiagoSoutoGit/website.git
   cbe5c40..1708ed3  update-readme -> update-readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# Cleaning Up By Deleting Branches and References

We are going to make a few more tweaks to the "update-readme" branch, synchronize those back to my local version, then synchronize all my changes to tracking branches locally, and then walk through the process of merging locally then deleting the branch both locally and remotely from the command line.


its super easy to just do a "git pull" and get the latest greatest of the updates on GitHub, but I want to show you another option. Eventually, we're going to be merging with master, so I'm going to go ahead and check out to there first.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (update-readme)
$ git status
On branch update-readme
Your branch is up to date with 'origin/update-readme'.

nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (update-readme)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
1
2
3
4
5
6
7
8
9
10
11

Now, I'm on the master branch, and if I do a "git pull" here, without specifying anything else, I will pull from master on GitHub, not from the other branch. If I show you the configuration, git config --global -e, at the bottom I have my push option with the "default = simple". And that simply means that whatever branch I'm currently on, only push and pull that particular branch;

[user]
	email = thiago.souto@yahoo.com.br
	name = ThiagoSoutoGit
[core]
	editor = \"C:\\Users\\Thiago Souto\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" --wait
[alias]
	hist = log --oneline --graph --decorate --all
1
2
3
4
5
6
7

However if I want to override that, I can use an option when I do a "pull". If I do a git pull --all, even though I'm currently on the master branch, Git will update all tracking branches at the same time; so master to master and then my "update-readme" to "update-readme".

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git config --global -e
hint: Waiting for your editor to close the file...

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git pull --all
Fetching origin
Warning: Permanently added the RSA host key for IP address '140.82.114.3' to the list of known hosts.
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:ThiagoSoutoGit/website
   1708ed3..6794090  update-readme -> origin/update-readme
Already up to date.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

lets merge

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git merge update-readme
Updating 4337f44..1708ed3
Fast-forward
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
1
2
3
4
5
6

Alright, we've integrated those changes, and it was such an easy merge we did a fast-forward, which means we just assumed that we made the commits directly on master. At least, from a history standpoint, that's what its going to appear to be.


So now we have a few commits that are ahead of 'origin/master', so lets push up those changes. Again, just do a "git push", and its going to work with our current branch, which is master, so it just pushed up our local master to remote master.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push
Total 0 (delta 0), reused 0 (delta 0)
To github.com:ThiagoSoutoGit/website.git
   4337f44..1708ed3  master -> master

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12

And now lets delete the branch

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -a
* master
  update-readme
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/update-readme

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -d update-readme
Deleted branch update-readme (was 1708ed3).

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/update-readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Great, now that we've integrated the changes, we no longer need the "update-readme" branch, so lets delete it. Ok, great, that branch has been deleted, and our local version of that branch is gone, but we still have the remote; and, if we switch back over to GitHub, do a quick refresh, its still listed up here as a recent branch and, if I drop down, its still listed here as well. I could go into branches and delete it, but lets do it from the command line.

To delete a remote branch from the command line, type git push; and then the name of the remote to use, which in our case is "origin", which references our GitHub repository; space; and in the syntax we start the name of the branch with a colon, doing so is telling Git to delete whatever the name is of the branch after the colon.

git push origin :update-readme

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push origin :update-readme
To github.com:ThiagoSoutoGit/website.git
 - [deleted]         update-readme
1
2
3
4

Alright lets do that. Great, when we did that, Git responded, saying that it deleted the "update-readme" which is on GitHub. lets go check it out. It instantly updated the little notification we had about recent branches; that's gone completely, and if I reload this page, do a quick dropdown, that other branch has been removed. And, we are down to a single branch, which, of course, is master. lets return to our terminal, and lets' check out all of our branch references. Using the command line, like we just did, to remove our remote branch Git automatically updated our references as well. So, we don't need to do the "git fetch" with the prune option.

# Pull with Rebase

We're going to explore the option of pulling with "rebase".


If you remember what rebase actually does, it rewinds the current commits that are on your branch to a point to where the branch you're merging in originally diverged;


then playing back the commits that happened on the branch that you're wanting to bring in;


and then, after that, playing on top of that any commits that have happened on the branch that you're currently on,


thus making any changes that you have include the changes that happened on the remote branch, but with your changes made ahead of them.


This is a good strategy when you're working on something, and you want to make sure that your changes are ahead of whatever's going on from the remote side.


  1. Now we are going from a clean repository and we are going to make a change on the README file on the master branch and leave a commit message.
Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git pull
Already up to date.
1
2
3
4
5
6
7
8
9
10


  1. I'm back in my terminal, and before I pull in any changes from GitHub, I'm going to make some changes on my local side first. Then commit and fetch.

lets tweak the "index.html" file, and lets just get rid of some of this conditional stuff that supports older version of IE. So I'm just going to delete that, and maybe even tweak the title. Once you're done with the edits, save and then close.


Again, I'm going to make my commit message fairly obvious so we can tell what happened after our rebase.

git commit -am "Updating index.html locally before rebase"

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ code index.html

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git commit -am "Updating index.html locally before rebase"
[master dac6a17] Updating index.html locally before rebase
 1 file changed, 2 insertions(+), 5 deletions(-)
1
2
3
4
5
6
7

If we do a git fetch its going to make this a little easier; you don't have to do the "git fetch", but for illustrations its going to help.


Basically, doing so will update our local Git with whatever changed on the remote side, so that now, when I do a "git status", it tells me that the local branch master has diverged from 'origin/master'.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git fetch
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:ThiagoSoutoGit/website
   1708ed3..4d353e1  master     -> origin/master

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

In this case, I could just merge in; I know, in doing so, its going to create an automatic merge which would result in a merge commit.

And that's ok, but what if I want to make sure that whatever I'm currently working on stays ahead of whatever's currently in GitHub.

  1. To do that, I can use a rebase; so type "git pull", and then use the option "--rebase" to cause a rebase instead of a merge when it comes in.

git pull --rebase

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git pull --rebase
First, rewinding head to replay your work on top of it...
Applying: Updating index.html locally before rebase
1
2
3
4

As the message says:

  1. its first rewinding the local branch,
  2. then it brings in our changes from GitHub,
  3. and then it applies any commits that we had on the local branch.
Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git hist
* 8bf131e (HEAD -> master) Updating index.html locally before rebase
* 4d353e1 (origin/master, origin/HEAD) ReadMe update on master on GitHub before Rebase
* 1708ed3 More tweakes to README
* cbe5c40 Tweaked reamdme
*   4337f44 Merge branch 'remove-ipsum'
|\
| * 3a3a669 Removing Ipsum file
* |   592b1de Merge pull request #2 from ThiagoSoutoGit/example
|\ \
| |/
|/|
| * 715e7ad Updating readme from branch example
|/
*   64b9aeb Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
|\
| * 83be714 Create new file -- filler text
|/
*   b9ce76c Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
|\
| * abe46aa Providing Title on index.html
* | c0d0887 Updating README
|/
* 64a922f Adding initial website files
* a48b427 Initial commit
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

So you can see, without history, that when it did the rebase it brought in the updates from GitHub, it placed them before our changes we had locally.


So, you can see the commit starting with "4d353e1" is what 'origin/master' is currently pointing to, which is our last commit from GitHub on 'origin/master' followed by the commit we just made on our local copy on master, which is updating the index file before the rebase.


However, that commit did not include any of the updates from GitHub, so that's an interesting distinction. Before, when we had that on master, it only had the changes that we included while we were here locally; it did not include anything that we changed on GitHub during this demo.


lets check it out; lets make sure that the changes from GitHub made it down to our local repository. First, lets do a "git status". We are now just one commit ahead of 'origin/master', and that's just the commit that includes the local changes that haven't been pushed back up to GitHub.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
1
2
3
4
5
6
7

lets check out the Readme file; we invoked our editor from the command line on our local system, and it shows us the changes that we made to this file while on GitHub. So, that means that we know that those changes made it to our local repository.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ ls -l
total 46
-rw-r--r-- 1 Thiago Souto 197121  3959 Apr  3 10:22 apple-touch-icon.png
-rw-r--r-- 1 Thiago Souto 197121   416 Apr  3 10:22 browserconfig.xml
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 css/
-rw-r--r-- 1 Thiago Souto 197121   766 Apr  3 10:22 favicon.ico
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 fonts/
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 img/
-rw-r--r-- 1 Thiago Souto 197121  5158 Apr  6 21:18 index.html
drwxr-xr-x 1 Thiago Souto 197121     0 Apr  3 10:22 js/
-rw-r--r-- 1 Thiago Souto 197121 11558 Apr  3 09:06 LICENSE
-rw-r--r-- 1 Thiago Souto 197121   101 Apr  6 21:18 README.md
-rw-r--r-- 1 Thiago Souto 197121  3482 Apr  3 10:22 tile.png
-rw-r--r-- 1 Thiago Souto 197121  1854 Apr  3 10:22 tile-wide.png

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ code README.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Alright, now that we're done, lets clean up by pushing up any changes we have back to GitHub: "git push". And since what we have locally already includes what was already on GitHub, all that's being pushed are the changes that we've made locally.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 379 bytes | 379.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:ThiagoSoutoGit/website.git
   4d353e1..8bf131e  master -> master
1
2
3
4
5
6
7
8
9
10
11


# GitHub Graphs

we're going to check out our network and branching graph on GitHub, and on the local system. lets start out on the local system. lets go back to our terminal, and I'm currently in the "website" Git repository, on the master branch, and I'm currently in a clean working directory state. Now that we've done lots of commits and some branching and merging, we should start to see some level of branching off and merging back when we do our graph. If I do a

git log --oneline --graph

the "--graph" option is what will denote the graph of our branches as they come and go. So, you can see some earlier commits were on other branches and they were eventually merged back into master. Some of the branches noted came from GitHub, and some were local.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git log --oneline --graph
* 8bf131e (HEAD -> master, origin/master, origin/HEAD) Updating index.html locally before rebase
* 4d353e1 ReadMe update on master on GitHub before Rebase
* 1708ed3 More tweakes to README
* cbe5c40 Tweaked reamdme
*   4337f44 Merge branch 'remove-ipsum'
|\
| * 3a3a669 Removing Ipsum file
* |   592b1de Merge pull request #2 from ThiagoSoutoGit/example
|\ \
| |/
|/|
| * 715e7ad Updating readme from branch example
|/
*   64b9aeb Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
|\
| * 83be714 Create new file -- filler text
|/
*   b9ce76c Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
|\
| * abe46aa Providing Title on index.html
* | c0d0887 Updating README
|/
* 64a922f Adding initial website files
* a48b427 Initial commit
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

To give some more context, I'm going to use my "hist" alias, which is equivalent to the "git log" command with several other options. Doing that will actually show us the branches that are involved with each of the commits.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (master)
$ git hist
* 8bf131e (HEAD -> master, origin/master, origin/HEAD) Updating index.html locally before rebase
* 4d353e1 ReadMe update on master on GitHub before Rebase
* 1708ed3 More tweakes to README
* cbe5c40 Tweaked reamdme
*   4337f44 Merge branch 'remove-ipsum'
|\
| * 3a3a669 Removing Ipsum file
* |   592b1de Merge pull request #2 from ThiagoSoutoGit/example
|\ \
| |/
|/|
| * 715e7ad Updating readme from branch example
|/
*   64b9aeb Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
|\
| * 83be714 Create new file -- filler text
|/
*   b9ce76c Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
|\
| * abe46aa Providing Title on index.html
* | c0d0887 Updating README
|/
* 64a922f Adding initial website files
* a48b427 Initial commit
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

But acctually they are giving the same result.

At gitHub we can go to Insights and Network to get some graphs about our history.



we're going to change the default branch of our GitHub repository. I'm currently logged into GitHub, and I'm in the "website" GitHub repository. I'm currently on the master branch, and at this point in time, it is the only branch we have;


however, in some work flows, the master branch represents what's currently in production, and active development should not happen on the master branch directly.


Instead, there should be another branch that is also long-lived where all the development effort goes, and then, periodically, those changes are merged back into master when the codebase reaches production ready status.


So, lets set up our new develop long-live branch

I'm going to expand out our branch dropdown, and in the search or create branch field, I'm going to create a branch called develop, then press enter. The branch named develop has been created, and is currently even with master.


Then, On Setting we change the default branch to develop



then we click on update.

GitHub will warn us since changing the default branch is not a trivial change; it does have some consequences, in particular how new pull requests and clones react. I'm going to click on "I understand, update the default branch."


the other side effect of changing the default branch is when we go to create our pull request, our destination, or base branch, is now defaulted to the new default branch, which is now develop.


When you clone you clone the develop branch.


If I wanted to get the master branch on my local system, I would have to check that branch out and fetch it down from the remote repository: "git checkout master". Since there was no master branch on our local system, Git went out to our remote, origin, and brought in the 'origin/master' branch and set that up as our local master branch. So now, we have both master and develop on our local system; however, develop is still the default branch on GitHub.

# Dealing with a Conflict while Pulling




# 🔟 GitHub Tags and Releases

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag unstable develop

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag
unstable

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag stable master

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tab
git: 'tab' is not a git command. See 'git --help'.

The most similar command is
        tag

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag
stable
unstable

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git hist
* 4c25f73 (HEAD -> develop, tag: unstable, origin/develop) readme
* 8bf131e (tag: stable, origin/master, origin/HEAD, master) Updating index.html locally before rebase
* 4d353e1 ReadMe update on master on GitHub before Rebase
* 1708ed3 More tweakes to README
* cbe5c40 Tweaked reamdme
*   4337f44 Merge branch 'remove-ipsum'
|\
| * 3a3a669 Removing Ipsum file
* |   592b1de Merge pull request #2 from ThiagoSoutoGit/example
|\ \
| |/
|/|
| * 715e7ad Updating readme from branch example
|/
*   64b9aeb Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
|\
| * 83be714 Create new file -- filler text
|/
*   b9ce76c Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
|\
| * abe46aa Providing Title on index.html
* | c0d0887 Updating README
|/
* 64a922f Adding initial website files
* a48b427 Initial commit

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

To list commits use git log --oneline

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git log --oneline
4c25f73 (HEAD -> develop, tag: unstable, origin/develop) readme
8bf131e (tag: stable, origin/master, origin/HEAD, master) Updating index.html locally before rebase
4d353e1 ReadMe update on master on GitHub before Rebase
1708ed3 More tweakes to README
cbe5c40 Tweaked reamdme
4337f44 Merge branch 'remove-ipsum'
592b1de Merge pull request #2 from ThiagoSoutoGit/example
3a3a669 Removing Ipsum file
715e7ad Updating readme from branch example
64b9aeb Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
83be714 Create new file -- filler text
b9ce76c Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
c0d0887 Updating README
abe46aa Providing Title on index.html
64a922f Adding initial website files
a48b427 Initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

To create annotated tags we use git tag -a v-alpha -m "Release (Alpha)" 64a922f

And we can use git show v0.1-alpha to show the annotated tag

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag -a v0.1-alpha -m "Release (Alpha)" 64a922f

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag
stable
unstable
v0.1-alpha

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git show v0.1-alpha
tag v0.1-alpha
Tagger: ThiagoSoutoGit <thiago.souto@yahoo.com.br>
Date:   Sat Apr 11 10:26:57 2020 +1200

Release (Alpha)

commit 64a922f20d206e2436531b6eb16030b6e1567dac (tag: v0.1-alpha)
Author: ThiagoSoutoGit <thiago.souto@yahoo.com.br>
Date:   Fri Apr 3 10:26:28 2020 +1300

    Adding initial website files

diff --git a/apple-touch-icon.png b/apple-touch-icon.png
new file mode 100644
index 0000000..600738f
Binary files /dev/null and b/apple-touch-icon.png differ
diff --git a/browserconfig.xml b/browserconfig.xml
new file mode 100644
index 0000000..46de5d3
--- /dev/null
+++ b/browserconfig.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Please read: http://msdn.microsoft.com/en-us/library/ie/dn455106.aspx -->
+<browserconfig>
+    <msapplication>
+        <tile>
+            <square70x70logo src="tile.png"/>
+            <square150x150logo src="tile.png"/>
+            <wide310x150logo src="tile-wide.png"/>
+            <square310x310logo src="tile.png"/>
+        </tile>
+    </msapplication>
+</browserconfig>
diff --git a/css/bootstrap-theme.css b/css/bootstrap-theme.css
new file mode 100644
index 0000000..c4cadf1
--- /dev/null
+++ b/css/bootstrap-theme.css
@@ -0,0 +1,470 @@
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

We can delete tags with git tag -d and the tag name.

Let's create another tag for the release v0.2-alpha

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag -a v0.2-alpha -m "Release 0.2 (Alpha)"

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag -d v0.2-alpha
Deleted tag 'v0.2-alpha' (was bcb1336)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag -a v0.2-alpha -m "Release 0.2 (Alpha)" b9ce76c

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git log --oneline
4c25f73 (HEAD -> develop, tag: unstable, origin/develop) readme
8bf131e (tag: stable, origin/master, origin/HEAD, master) Updating index.html locally before rebase
4d353e1 ReadMe update on master on GitHub before Rebase
1708ed3 More tweakes to README
cbe5c40 Tweaked reamdme
4337f44 Merge branch 'remove-ipsum'
592b1de Merge pull request #2 from ThiagoSoutoGit/example
3a3a669 Removing Ipsum file
715e7ad Updating readme from branch example
64b9aeb Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
83be714 Create new file -- filler text
b9ce76c (tag: v0.2-alpha) Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
c0d0887 Updating README
abe46aa Providing Title on index.html
64a922f (tag: v0.1-alpha) Adding initial website files
a48b427 Initial commit
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

Also Release 0.3 (Beta)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag -a v0.3-beta -m "Release 0.3 (Beta)" 64b9aeb

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git log --oneline
4c25f73 (HEAD -> develop, tag: unstable, origin/develop) readme
8bf131e (tag: stable, origin/master, origin/HEAD, master) Updating index.html locally before rebase
4d353e1 ReadMe update on master on GitHub before Rebase
1708ed3 More tweakes to README
cbe5c40 Tweaked reamdme
4337f44 Merge branch 'remove-ipsum'
592b1de Merge pull request #2 from ThiagoSoutoGit/example
3a3a669 Removing Ipsum file
715e7ad Updating readme from branch example
64b9aeb (tag: v0.3-beta) Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
83be714 Create new file -- filler text
b9ce76c (tag: v0.2-alpha) Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
c0d0887 Updating README
abe46aa Providing Title on index.html
64a922f (tag: v0.1-alpha) Adding initial website files
a48b427 Initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag
stable
unstable
v0.1-alpha
v0.2-alpha
v0.3-beta
1
2
3
4
5
6
7

# Pushing Local Tags to GitHub

First let's make sure we have received all the updates from GitHub with git pull

Then to send our commits the we currently have on our local repository lets do a git push

To push a tag we do git push origin stable

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag
stable
unstable
v0.1-alpha
v0.2-alpha
v0.3-beta

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git pull
Already up to date.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git push
Everything up-to-date

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git push origin stable
Total 0 (delta 0), reused 0 (delta 0)
To github.com:ThiagoSoutoGit/website.git
 * [new tag]         stable -> stable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

After we push the tag we can download the version of the repository from GitHub.



To push all tags we use git push --tags

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git push --tags
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 471 bytes | 157.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:ThiagoSoutoGit/website.git
 * [new tag]         unstable -> unstable
 * [new tag]         v0.1-alpha -> v0.1-alpha
 * [new tag]         v0.2-alpha -> v0.2-alpha
 * [new tag]         v0.3-beta -> v0.3-beta
1
2
3
4
5
6
7
8
9
10
11
12
13


# Deleting Tags

We can delete tags with git tag -d and the tag name.

To delete a tag onGitHub from the local repository we can push nothing to the tag name like so git push origin :v0.2-alpha

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git push origin :v0.2-alpha
To github.com:ThiagoSoutoGit/website.git
 - [deleted]         v0.2-alpha
1
2
3
4

# Updating Tags Creating a Floating Tag

Let's change the README.md file and commit.

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ code README.md

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git status
On branch develop
Your branch is up to date with 'origin/develop'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

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

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git commit -am "Updating README with puupose for tags"
[develop 1d5c6fc] Updating README with puupose for tags
 1 file changed, 2 insertions(+)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 335 bytes | 335.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:ThiagoSoutoGit/website.git
   4c25f73..1d5c6fc  develop -> develop

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git log --online --decorate
fatal: unrecognized argument: --online

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git log --oneline --decorate
1d5c6fc (HEAD -> develop, origin/develop) Updating README with puupose for tags
4c25f73 (tag: unstable) readme
8bf131e (tag: stable, origin/master, origin/HEAD, master) Updating index.html locally before rebase
4d353e1 ReadMe update on master on GitHub before Rebase
1708ed3 More tweakes to README
cbe5c40 Tweaked reamdme
4337f44 Merge branch 'remove-ipsum'
592b1de Merge pull request #2 from ThiagoSoutoGit/example
3a3a669 Removing Ipsum file
715e7ad Updating readme from branch example
64b9aeb (tag: v0.3-beta) Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
83be714 Create new file -- filler text
b9ce76c (tag: v0.2-alpha) Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
c0d0887 Updating README
abe46aa Providing Title on index.html
64a922f (tag: v0.1-alpha) Adding initial website files
a48b427 Initial commit
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

Now Let's update our tag to point to the new commit ID. To update an existing tag we use -f, like:

git tag -f unstable 1d5c6fc

If you don't specify the commit It will point to the HEAD like git tag -f unstable

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git tag -f unstable 1d5c6fc
Updated tag 'unstable' (was 4c25f73)

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git log --oneline --decorate
1d5c6fc (HEAD -> develop, tag: unstable, origin/develop) Updating README with puupose for tags
4c25f73 readme
8bf131e (tag: stable, origin/master, origin/HEAD, master) Updating index.html locally before rebase
4d353e1 ReadMe update on master on GitHub before Rebase
1708ed3 More tweakes to README
cbe5c40 Tweaked reamdme
4337f44 Merge branch 'remove-ipsum'
592b1de Merge pull request #2 from ThiagoSoutoGit/example
3a3a669 Removing Ipsum file
715e7ad Updating readme from branch example
64b9aeb (tag: v0.3-beta) Merge pull request #1 from ThiagoSoutoGit/feature-lipsum
83be714 Create new file -- filler text
b9ce76c (tag: v0.2-alpha) Merge branch 'master' of github.com:ThiagoSoutoGit/my-website
c0d0887 Updating README
abe46aa Providing Title on index.html
64a922f (tag: v0.1-alpha) Adding initial website files
a48b427 Initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

If we try to push the tag we are going to receive an error because unstable already exist in another place

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git push origin unstable
To github.com:ThiagoSoutoGit/website.git
 ! [rejected]        unstable -> unstable (already exists)
error: failed to push some refs to 'git@github.com:ThiagoSoutoGit/website.git'
hint: Updates were rejected because the tag already exists in the remote.
1
2
3
4
5
6

We can delete the tag and put a new one or we can push force with git push --force origin unstable

Thiago Souto@MSI MINGW64 ~/Desktop/GitProjects/website (develop)
$ git push --force origin unstable
Total 0 (delta 0), reused 0 (delta 0)
To github.com:ThiagoSoutoGit/website.git
 + 4c25f73...1d5c6fc unstable -> unstable (forced update)
1
2
3
4
5

# Starting a Release on GitHub

The difference between releases and tags are the realese notes