Installation and Configuration
- First thing first, you can easily install Git on all 3 mainstream OS, Windows, Linux, OSX.
Get Windows Installer on https://git-for-windows.github.io/.
Note in Windows, the official Git tool is called "Git for Windows" as well as msysgit. They ' re aimed at the same thing.
- git provide a command tool named git Config for environment configuration.
You should configure some basic information with least for better using experience.
Editor & Merge tool would be need other stand alone tools, e.g. Gvim, KDIFF3, etc.
Here we don't configure external editor but get the kdiff3 right here Http://sourceforge.net/projects/kdiff3/file S/latest/download?source=files.
- Editor
$ git config--global core.editor gvim
- Merge Tool
Say we ' re using KDIFF3 in Windows for Comparison and Merge branch.
$ git config--global merge.tool kdiff
$ git config--global mergetool.kdiff3.path "Your path to Kdiff3.exe"
- Ps:the configuration could be list using below commands:
$ git config--list
Or If you need to check the value of a configuration, use:
$ git config user.name
- as sometimes you'll need to clone a remote repository, and your ' re trying to use the SSH in for remote operations. It ' s time for some SSH stuffs.
- Check whether your SSH keys exists:
$ ls ~/.ssh
There should is text files similar to below, which contains the public key & end with your email.
id_dsa.pub
id_rsa.pub
- Generate your new SSH keys:
$ ssh-keygen-t rsa-b 4096-c "[email protected]"
- Ensure Ssh-agent is enabled:
# Start the ssh-agent in the background
$ ssh-agent-s
# Agent PID 59566
- Add your SSH key to the ssh-agent:
$ Ssh-add ~/.ssh/id_rsa
- Add your SSH key to your account, copy the whole public key and paste to your remote Git repository server such as GitHub, GitLab, etc.
$ clip < ~/.ssh/id_rsa.pub
- Ps:this ssh-to-your private key to identify your user information, it is used when the repository URL happened to Be something similar to git://example.com/repo.git.
Dance at local
Remote Repository
- Show me the verbose
$ git remote-v
#origin Git://example.com/project.git
#peter Git://hello.com/project.git
#lan//dell-pc/d/path/project.git
- ADD Remote Repository
- Using git remote Add to configure a new repository.
$ git remote add alias Git://github.com/paulboone/ticgit.git
Once you has your remote repositories, you can specify you'll choose which repository to fetch data:
$ git fetch Peter
Unpacking objects:100% (44/44), done.
From Git://github.com/paulboone/ticgit
* [New branch] master, Peter/master
* [New branch] Ticgit-Pter/ticgit
- Push local commits to remote repository
Branch Model
The widely used part in Git. Efficient, Clear, and works great.
- Create a new branch
$ git Branch Testing
- In your local, there's always a HEAD pointer point to a specified version of your working branch. That is:
- As the image says, Master & testing were the branches exist. HEAD now point to master. Because git branch won't change the working branch anyway.
- Now your ' re going to check out the new branch for working:
$ git checkout Testing
The HEAD pointer has been redirected. And now the checkout command is used to switch branches, instead of discard changes.
- After switch and commit different things in both branches, they might look like:
This model explains why we should use Branch to control our development, and how easily it's to use.
- Basic workflow of development based on Git
- Firstly you ' ve decided to work on a new feature or a bug fix, say #iss53.
$ git Branch iss53
$ git checkout iss53
- Now you have the below model look like:
- Some work has been done and the progress moved on:
$ git commit-m "Add something"
- But there ' re some urgent fix should is done now, you'll switch back to complete the hotfix:
- now we merge the hotfix to master and push it to remote server:
- Thin GS were moving smoothly and the hotfix can be deleted safely, and the iss53 could be keep developing again.
$ git branch-d hotfix
#Deleted Branch Hotfix (3A0874C).
$ git checkout iss53
$ git commit-m "other features"
- when the iss53 have been finished, just merge the iss53 into master:
$ git checkout master
$ git merge iss53
Even though the process of merge is different from the hotfix one , the git decided how to merge these-branches itself. Finding the Common ancestor, merge the commits, and create a new commit (which is a special commit named "Merge Commit"). /p>
- What if there ' re conflict occurred when merging? At the moment, all the conflict files would be listed as "unmerged files".
$ git mergetool
merge tool candidates:kdiff3 Tkdiff Xxdiff meld Gvimdiff Opendiff emerge Vimdiff
merging the files:index.html
normal merge conflict for ' index.html ':
{local}: Modified
{remote}: Modified
hit return to start Merge Resolution tool (OPENDIFF):
After that, the status would become modified again and could is committed now.
- Actually, you can also merge the Master branch to your #iss53 anytime, if other ' s important changes is needed. And then push the local branch to the remote repository, create a merge request. Waiting for someone who have a write access right to merge your branch into master. This is a acceptable workflow as well.
$ git checkout iss53
$ GIT fetch origin
$ git merge origin/master iss53
$ GIT push origin iss53
This kind of process could is completed easier via rebase:
$ git checkout iss53
$ git rebase Master
$ GIT push origin iss53
The rebase command would generate a clearer development history:
- Tracking Branch
- A local branch checkout from remote server is called a tracking branch.
$ git checkout-b localfix origin/serverfix
Branch Localfix set up to track remote Branch refs/remotes/origin/serverfix.
Switched to a new branch "Localfix"
The branch name can be a same as branch on server side.
$ GIT push origin serverfix:localfix or
$ Git push Origin serverfix (if the name were the same)
Begin using Git