Git is a distributed revision control and source code management (SCM) system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows. Git was initially designed and developed by Linus Torvalds for Linux kernel development in 2005, and has since become the most widely adopted version control system for software development.
As with most other distributed revision control systems, and unlike most client–server systems, every Git working directory is a full-fledged repository with complete history and full version-tracking capabilities, independent of network access or a central server. Like the Linux kernel, Git is free software distributed under the terms of the GNU General Public License version 2.
Official Website git-scm.com
GitHub is a Git repository web-based hosting service which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding own features. Unlike Git, which is strictly a command-line tool, GitHub provides a web-based graphical interface and desktop as well as mobile integration. It also provides access control and several collaboration features such as wikis, task management, and bug tracking and feature requests for every project.
Now let's start.
You can download Git GUI Clients for your OS form
git-scm.com or use git command in terminal.
For Microsoft Windows
Generate SSH Keys
$ ssh-keygen -t rsa -C "[email protected]" # Creates a new ssh key using the provided email # Generating public/private rsa key pair.# Enter file in which to save the key (/home/you/.ssh/id_rsa):
After press Enter will be prompted to enter a password and confirm password:
Enter passphrase (empty for no passphrase): [Type a passphrase]# Enter same passphrase again: [Type passphrase again]
Then see this information similar to that showed the success of key generation
Your identification has been saved in /home/you/.ssh/id_rsa. # Your public key has been saved in /home/you/.ssh/id_rsa.pub.# The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
Go to GitHub official website, register an account.
In Github SSH key and enter the server detects the connection success. Log in to your Github account, enter "Account settings/SSH Keys", you can enter just generated key.
Try to detect what SSH connection to Github git server.
$ ssh -T [email protected] # Attempts to ssh to github
Might see such a warning, that's doesn't matter, enter "yes" and press Enter.
The authenticity of host 'github.com (126.96.36.199)' can't be established.# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.# Are you sure you want to continue connecting (yes/no)?
Finally, you can see this message a successful connection:
Hi username! You've successfully authenticated, but GitHub does not # provide shell access.
$ git config --global user.name "Your Name Here" # Sets the default name for git to use when you commit $ git config --global user.email "[email protected]" # Sets the default email for git to use when you commit
Creates a directory for your project called "Hello-World" in your user directory:
$ mkdir ~/Hello-World
Changes the current working directory to your newly created directory:
$ cd ~/Hello-World
Sets up the necessary Git files. Initialized empty Git repository in
$ git init
Creates a file called
README in your Hello-World directory:
$ touch README
README file, adding it to the list of files to be committed:
$ git add README
Commits your files, adding the message
$ git commit -m 'first commit'
Creates a remote named
origin pointing at your GitHub repogit push origin master# Sends your commits in the
master branch to GitHub:
$ git remote add origin https://github.com/username/Hello-World.git
Clones your fork of the repo into the current directory in terminal
$ git clone https://github.com/username/Spoon-Knife.git
$ git checkout -b feature_x
$ git checkout master
$ git branch -d feature_x
Unless you will be pushed to the remote branch warehouse, or the branch is not seen for others.
$ git push origin <branch>
Pull and Merge
$ git pull
Merge other branch to
$ git merge <branch>
In both cases, git will try to automatically merge changes. Unfortunately, the automatic consolidation is not the bottom in successful and may lead to conflicts (conflicts). This time you will need to modify these files come meat merge these conflicts (conflicts) a. After he was done, you need to perform this command:
$ git add <filename>
Before to the merger changes, they can use the following command to view:
$ git diff <source_branch> <target_branch>
Fix Some Error
- How do you get git to always pull from a specific branch?
$ git config branch.master.remote origin $ git config branch.master.merge refs/heads/master
- Require input github account and password when git push command
When access to a remote GitHub repository, there are ways ssh and https mode.
URL address two different ways, authentication methods are also different. When using ssh key save on future can no longer enter the account password, but https can not. So if you want to no longer enter the account password, one way is to git clone mode when using ssh, another way is to modify the config file .git directory of existing projects in the url, as follows:
[remote "origin"] url = [email protected]:example/project.git fetch = +refs/heads/*:refs/remotes/origin/*