What is GIT

Git is a distributed revision control and source code management system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development. Git is a free software distributed under the terms of the GNU General Public License version 2.
Version Control System (VCS) is a software that helps software developers to work together and maintain a complete history of their work.
Listed below are the functions of a VCS:
  • Allows developers to work simultaneously.
  • Does not allow overwriting each other’s changes.
  • Maintains a history of every version.
Following are the types of VCS:
  • Centralized version control system (CVCS).
  • Distributed/Decentralized version control system (DVCS).
Some popular distributed version control systems are
GIT
SVN

git_life_cycle:
Git Tutorial

GIT Clients


Install GIT on ubuntu

sudo apt-get install git-core gitg git-all

Connecting to GitHub with SSH
https://help.github.com/articles/connecting-to-github-with-ssh/

Create A Repo
  • In the upper-right corner of any page, click , and then click New repository.
  • Type a short, memorable name for your repository. For example, "wicket-examples7x".
  • Optionally, add a description of your repository. For example, "My first repository on GitHub."
  • Choose between creating a public or private repository.
    Public repositories are a great choice for getting started. They're visible to any user on GitHub, so you can benefit from a collaborative community.Private repositories require a little more setup. They're only available to you, the repository owner, as well as any collaborators you choose to share with. Private repositories are only available for paid accounts. For more information, see "GitHub's billing plans."
  • Select Initialize this repository with a README.
  • Click Create repository.
Congratulations! You've successfully created your first repository, and initialized it with a README file.

Commit the first changes
Let's commit a change to the README file.
  • In your repository's list of files, click README.md.
  • Above the file's content, click .
  • On the Edit file tab , type some information about yourself.
  • Above the new content, click Preview changes.
  • Review the changes you made to the file. You'll see the new content in green.
  • At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file. You can attribute the commit to more than one author in the commit message. For more information, see "Creating a commit with multiple co-authors."
  • Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
  • Click Propose file change.
Using GIT by command line on ubuntu
$ git clone git@github.com:damithme/angular4-cli-spring-boot-example.git
$ git branch 
* master
git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/Part-1
  remotes/origin/master
  remotes/origin/part-1
  remotes/origin/part-2
$ git checkout -b part-2
Switched to a new branch 'part-2'
$ git status
On branch part-2
nothing to commit, working directory clean
$ git branch
  master
* part-2


gitg

mkdir temp
cd temp
git clone -b Part-1 --single-branch git@github.com:damithme/angular4-cli-spring-boot-example.git
git branch -a
* Part-1
  remotes/origin/Part-1
git status
On branch Part-1
Your branch is up-to-date with 'origin/Part-1'.
git diff

$ git clone git@github.com:laithanhtung/wicket-examples7x.git
$ cd wicket-examples7x
$ git add header.txt 
$ git commit -m "add header file"
[master c50cc68] add header file
 1 file changed, 15 insertions(+)
 create mode 100644 header.txt
$ git config --global user.email "tungthanh.lai@gmail.com"
$ git config --global user.name "Lai Thanh Tung"
$ git commit -m "optional template added, it works generally"
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
$ gitg
$ git push

and header.txt file is upload into master branch on github.

$ git checkout remotes/origin/master .

Fork a Repo

2-Install Mercurial on ubuntu

 $ sudo apt-get install mercurial meld

Create ~/.hgrc file with following content:
[ui]
# Name data to appear in commits
username = Tung Lai <tungthanh.lai@gmail.com>

ssh = ssh -C

Set up SSH on macOS/Linux to connect Bitbucket

Permission denied (publickey)
--
ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/administrator/.ssh/id_rsa): Enter
Enter passphrase (empty for no passphrase): 123456a@
Enter same passphrase again: 123456a@
Your identification has been saved in /home/administrator/.ssh/id_rsa.
Your public key has been saved in /home/administrator/.ssh/id_rsa.pub.
The key fingerprint is:
51:af:6e:75:00:30:2d:8e:6b:bc:0e:1f:7a:23:fd:42
The key's randomart image is:
+--[ RSA 2048]----+
|        ooo      |
|        .o.o     |
|       o..  o    |
|      . .. . .   |
|     . .S . . .  |
|      E  . . .   |
|    .+..  o      |
|    .+*. .       |
|    .+o+.        |
+-----------------+
ls ~/.ssh 
id_rsa  id_rsa.pub  keys  known_hosts

cat ~/.ssh/id_rsa.pub
=> key gen =
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDbETfvwEdUGIkg9OnkqAyfOcXo+WXa6ogyJ49KDnt6J0yr1Tmh2c6XXiYrAmeBZerXgw2P7UkqfCQsaUSkTB1elvPUxxtVZDKyjuQVZnsDGSpPQRymoXN7uSL5kw+15zPz0RW5DxKV2QYtd1jSOKgCEsxI0n59n3/WmpFuQraYpiFJnSAIw/In1kflyzxu4cKHPyry0I4NmjtATphRbZ/UznzISXtw3x1IpjAks/TpzjVcIGXxjdSQ9MDnh/RE499BPlYRygGq3H1X32KhezUSryBebRIHk/EUh9zmryByKBmfXJtV4UFwb7XjlI1ewdBdNDhza3JQ8aSQxA8hRHGb, for example

From Bitbucket, click Add key.
Enter a Label for your new key, for example, Default public key.
Paste the copied public key into the SSH Key field.
Save

$ ssh -T git@bitbucket.org
logged in as laithanhtung.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

NOTE: use git bash if OS is windows.

Every thing is done. Now we can clone a bitbucket repository:

hg clone ssh://hg@bitbucket.org/sw-samuraj/blog-wicket-spring-rest
destination directory: blog-wicket-spring-rest
requesting all changes
adding changesets
adding manifests
adding file changes
added 80 changesets with 112 changes to 33 files (+1 heads)
updating to branch default
25 files updated, 0 files merged, 0 files removed, 0 files unresolved

Reference:
https://nvie.com/posts/a-successful-git-branching-model/