Configure Git and Github

Wiki

Git

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

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.

Website github.com

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

Install

Configure Git and Github

Configure Git and Github

Configure Git and Github

Configure Git and Github

Configure Git and Github

Configure Git and Github

Configure Git and Github

Configure Git and Github

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]

Configure Git and Github

Configure Git and Github

Go to GitHub official website, register an account.

Configure Git and Github

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.

Configure Git and Github

$ 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 (207.97.227.239)' 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.

Configure Git and Github

$ 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
Simple Guide

Push

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 /Users/you/Hello-World/.git/:

$ git init

Creates a file called README in your Hello-World directory:

$ touch README

Stages your README file, adding it to the list of files to be committed:

$ git add README

Commits your files, adding the message first commit:

$ 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

Clone

Clones your fork of the repo into the current directory in terminal

$ git clone https://github.com/username/Spoon-Knife.git

Branch

Create feature_x branch:

$ git checkout -b feature_x

Back to master branch:

$ git checkout master

Delete feature_x branch:

$ 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

Update:

$ git pull

Merge other branch to master branch:

$ 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/*
0.00 avg. rating (0% score) - 0 votes