How to use Git on Windows.

Source: Internet
Author: User
Tags how to use git

How to use Git on Windows.


First step: Register your GitHub account.
Sign up for your GitHub account and create a resource warehouse core.




Step two: Install Git.
To install git, I'm using the git version of Git-1.9.5-preview20150319.exe,git after installing the Git bash and git Gui (visual operation) in the Start menu.
All the exercises below are under Gitbash. In addition, the/d/ilucky/git/workspace (master) directory is the last time the Git workspace was tested.




Step three: Configure the git user.
The GIT user is configured so that git can track who has changed the code and we need to set the username and mailbox.


[Email protected]/d/ilucky/git/workspace (master)
$ git config--global user.name sidongxue


[Email protected]/d/ilucky/git/workspace (master)
$ git config--global user.email [email protected]


After you have set up git, you can find the. gitconfig file in the user directory of the system disk and open a. gitconfig file with the following information:
[User]
Name = Sidongxue
email = [email protected]




Fourth step: Create a local git workspace.
[Email protected]/d/ilucky/git/workspace (master)
$ cd/d/ilucky/git/core


[Email protected]/d/ilucky/git/core
$ git init
Initialized empty Git repository in d:/ilucky/git/core/.git/


[Email protected]/d/ilucky/git/core (master)


Once you've created your local git workspace, you'll see a hidden file in the D/ilucky/git/core directory. Git.
At the same time, look for the. gitconfig file in the user directory of the system disk, open the. gitconfig file with the following:
[GUI]
Recentrepo = D:/ilucky/git/gittest




Fifth step: Load the project file into the local git workspace.
Copy the created test project git to the D:/ilucky/git/core directory and execute the following instructions to load the project into a local git workspace.
[Email protected]/d/ilucky/git/core (master)
$ git Add.
WARNING:LF is replaced by CRLF in Git/.mymetadata.
The file would have their original line endings in your working directory.
WARNING:LF is replaced by CRLF in Git/webroot/meta-inf/manifest. Mf.
The file would have their original line endings in your working directory.
WARNING:LF is replaced by CRLF in Git/webroot/web-inf/web.xml.
The file would have their original line endings in your working directory.


[Email protected]/d/ilucky/git/core (master)
$




Sixth step: Submit a project file that has been loaded into your local git workspace.
Comments are usually written on the commit, for example: Use test as a comment for the first commit,
Once the commit is complete, you can roll back to this state at any time, and if you need to check git status, you can query through the git status command.
[Email protected]/d/ilucky/git/core (master)
$ git commit-m "test"
[Master (root-commit) b8b6476] Test
WARNING:LF is replaced by CRLF in Git/.mymetadata.
The file would have their original line endings in your working directory.
WARNING:LF is replaced by CRLF in Git/webroot/meta-inf/manifest. Mf.
The file would have their original line endings in your working directory.
WARNING:LF is replaced by CRLF in Git/webroot/web-inf/web.xml.
The file would have their original line endings in your working directory.
Changed files, 171 insertions (+)
Create mode 100644 Git/.classpath
Create mode 100644 Git/.mymetadata
Create mode 100644 Git/.project
Create mode 100644 Git/.settings/.jsdtscope
Create mode 100644 git/.settings/org.eclipse.jdt.core.prefs
Create mode 100644 git/.settings/org.eclipse.wst.common.component
Create mode 100644 Git/.settings/org.eclipse.wst.common.project.facet.core.xml
Create mode 100644 Git/.settings/org.eclipse.wst.jsdt.ui.supertype.container
Create mode 100644 Git/.settings/org.eclipse.wst.jsdt.ui.supertype.name
Create Mode 100644 git/webroot/meta-inf/manifest. Mf
Create mode 100644 Git/webroot/web-inf/classes/com/ilucky/git/user.class
Create mode 100644 Git/webroot/web-inf/web.xml
Create mode 100644 git/webroot/index.jsp
Create mode 100644 Git/src/com/ilucky/git/user.java


[Email protected]/d/ilucky/git/core (master)
$ git status
On Branch Master
Nothing-to-commit, working directory clean




Seventh Step: Upload files submitted to the Git workspace to GitHub.
Note: You will need to enter the user name and password for GitHub registration.
[Email protected]/d/ilucky/git/core (master)
$ git Remote add Origin https://github.com/IluckySi/core.git


[Email protected]/d/ilucky/git/core (master)
$ GIT push origin master
Username for ' https://github.com ': iluckysi
Password for ' https://[email protected] ':
Counting objects:29, done.
Delta compression using up to 4 threads.
Compressing objects:100% (16/16), done.
Writing objects:100% (29/29), 4.01 KiB | 0 bytes/s, done.
Total (delta 0), reused 0 (Delta 0)
To Https://github.com/IluckySi/core.git
* [New branch] Master, master
Branch Master set up to track remote Branch master from Origin.


[Email protected]/d/ilucky/git/core (master)
Finally, log on to GitHub and you'll see the commit message.




Eighth step: Create a branch.
Creating a branch is a stand-alone version of creating a project, independent of your main branch.
Create a branch on the main branch, develop new features, and then merge to the main branch when the feature development is completed and tested.
[Email protected]/d/ilucky/git/core (master)
$ git checkout-b core_branch
Switched to a new branch ' Core_branch '


[Email protected]/d/ilucky/git/core (core_branch)
$ git Branch
* Core_branch
Master


[Email protected]/d/ilucky/git/core (core_branch)
By doing this, all of the actions you now have on the IDE are under the branch and do not affect the main branch.




Nineth Step: Merge the branches.
Test: Add a usertype class on the branch.
Before merging the branches, you first perform steps fifth and sixth, load the project files, and submit the project files.
Then switch to the main branch and finally merge the branches.
[Email protected]/d/ilucky/git/core (core_branch)
$ git Add.
WARNING:LF is replaced by CRLF in Git/.mymetadata.
The file would have their original line endings in your working directory.


[Email protected]/d/ilucky/git/core (core_branch)
$ git commit-m "core_branch add Usertype"
[Core_branch c143b5a] core_branch add usertype
4 files changed, insertions (+)
Rewrite Git/webroot/web-inf/classes/com/ilucky/git/user.class (100%)
Create mode 100644 Git/webroot/web-inf/classes/com/ilucky/git/usertype.class
Create mode 100644 Git/src/com/ilucky/git/usertype.java


[Email protected]/d/ilucky/git/core (core_branch)
$ git Checkout Master
Switched to branch ' master '
Your branch is up-to-date with ' origin/master '.


[Email protected]/d/ilucky/git/core (master)
$ git Merge Core_branch
Updating b8b6476. c143b5a
Fast-forward
Git/webroot/web-inf/classes/com/ilucky/git/user.class | Bin 723, 1191 bytes
.../web-inf/classes/com/ilucky/git/usertype.class | Bin 0, 873 bytes
Git/src/com/ilucky/git/user.java | 15 +++++++++++++++
Git/src/com/ilucky/git/usertype.java | 5 +++++
4 files changed, insertions (+)
Create mode 100644 Git/webroot/web-inf/classes/com/ilucky/git/usertype.class
Create mode 100644 Git/src/com/ilucky/git/usertype.java


[Email protected]/d/ilucky/git/core (master)
$




Tenth step: Discard Branches
Test: Create a file Testdel on the branch.
[Email protected]/d/ilucky/git/core (core_branch)
$ git Add.


[Email protected]/d/ilucky/git/core (core_branch)
$ git commit-m "Drop branch"
[Core_branch 57f8eb6] Drop Branch
2 files changed, 5 insertions (+)
Create mode 100644 Git/webroot/web-inf/classes/com/ilucky/git/testdel.class
Create mode 100644 Git/src/com/ilucky/git/testdel.java


[Email protected]/d/ilucky/git/core (core_branch)
$ git Checkout Master
Switched to branch ' master '
Your branch is up-to-date with ' origin/master '.


[Email protected]/d/ilucky/git/core (master)
$
Finally to the IED, the Testdel file does not.




11th Step: Delete a branch
Test: Add a TestDel2 class on the branch.
If the branch is not merged, you will get an error message as follows:
[Email protected]/d/ilucky/git/core (master)
$ git branch-d core_branch
Error:the branch ' Core_branch ' is not fully merged.
If you're sure want to delete it, run ' git branch-d core_branch '.


[Email protected]/d/ilucky/git/core (master)
$
You can also force the deletion of a branch, as follows:
[Email protected]/d/ilucky/git/core (master)
$ git branch-d core_branch
Deleted Branch Core_branch (was 57f8eb6).




12th step: Roll back to the previous state.
It is especially important to look at the log first, and then see which state to scroll to, which is the comment on each commit.
[Email protected]/d/ilucky/git/core (master)
$ git log
Commit d0bdfba72d1ec57c611e3673b6edafddd8385556
Author:sidongxue <[email protected]>
Date:fri 22 17:51:14 2015 +0800


Aa


Commit 99812A9193F675AE233FECEDCC2469EC521FF7FD
Author:sidongxue <[email protected]>
Date:fri 22 17:28:47 2015 +0800


Test


Commit B2aeac18798a01437e8a8c7a7d86e94739a9ccd7
Author:sidongxue <[email protected]>
Date:fri 22 17:23:26 2015 +0800


Ss


Commit B0bf3a3ff823e5f23b2d4cf0f617cba67370cda6
Author:sidongxue <[email protected]>
Date:fri 22 17:18:36 2015 +0800


Hello


Commit C143B5A950099580A31840B5045196851015C7FC
Author:sidongxue <[email protected]>
Date:fri 22 16:10:00 2015 +0800


Core_branch Add usertype


Commit B8b64766c6f66511ca8061911e019b3066c157f5
Author:sidongxue <[email protected]>
Date:fri 22 15:41:07 2015 +0800


Test


[Email protected]/d/ilucky/git/core (master)
$ git checkout B8b64766c6f66511ca8061911e019b3066c157f5
Note:checking out ' b8b64766c6f66511ca8061911e019b3066c157f5 '.


You're in the ' detached HEAD ' state. You can look around, make experimental
Changes and commit them, and you can discard any commits do in this
State without impacting any branches by performing another checkout.


If you want to create a new branch to retain commits your create, may
Do and later by Using-b with the checkout command again. Example:


Git checkout-b new_branch_name


HEAD is now at b8b6476 ... test


[Email protected]/d/ilucky/git/core ((b8b6476 ...))
$




12th step: Download the remote code base.
[Email protected]/d/ilucky/git/core ((b8b6476 ...))
$ git clone https://github.com/IluckySi/core.git
Cloning into ' core ' ...
Remote:counting objects:108, done.
Remote:compressing objects:100% (47/47), done.
Remote:total 108 (Delta), reused 104 (delta), pack-reused 0
Receiving objects:100% (108/108), 10.19 KiB | 0 bytes/s, done.
Resolving deltas:100% (14/14), done.
Checking connectivity ... done.


[Email protected]/d/ilucky/git/core ((b8b6476 ...))


Note: If you have already worked on a local project, just want to get its latest version from the remote code base and move to the root of the project, you need to execute the following command:
$ Git pull Origin Master
From Https://github.com/IluckySi/core
* Branch Master--Fetch_head
Updating b8b6476. D0bdfba
Fast-forward
.../web-inf/classes/com/ilucky/git/testdrop.class | Bin 0, 279 bytes
.../web-inf/classes/com/ilucky/git/testuser.class | Bin 0, 279 bytes
Git/webroot/web-inf/classes/com/ilucky/git/user.class | Bin 723, 1191 bytes
.../web-inf/classes/com/ilucky/git/usertype.class | Bin 0, 873 bytes
Git/src/com/ilucky/git/testdrop.java | 5 +++++
Git/src/com/ilucky/git/testuser.java | 5 +++++
Git/src/com/ilucky/git/user.java | 15 +++++++++++++++
Git/src/com/ilucky/git/usertype.java | 5 +++++
8 files changed, insertions (+)
Create mode 100644 Git/webroot/web-inf/classes/com/ilucky/git/testdrop.class
Create mode 100644 Git/webroot/web-inf/classes/com/ilucky/git/testuser.class
Create mode 100644 Git/webroot/web-inf/classes/com/ilucky/git/usertype.class
Create mode 100644 Git/src/com/ilucky/git/testdrop.java
Create mode 100644 Git/src/com/ilucky/git/testuser.java
Create mode 100644 Git/src/com/ilucky/git/usertype.java


[Email protected]/d/ilucky/git/core ((D0BDFBA ...))






Question: If the checkout master times is wrong, the head node of the local master and remote master is no longer on a commit node,
Need to push again.
[Email protected]/d/ilucky/git/core (master)
$ git Checkout Master
Already on ' master '
Your Branch is ahead of ' Origin/master ' by 3 commits.
(use "Git push" to publish your local commits)


[Email protected]/d/ilucky/git/core (master)
$ GIT push origin master
Username for ' https://github.com ': iluckysi
Password for ' https://[email protected] ':
Counting objects:59, done.
Delta compression using up to 4 threads.
Compressing objects:100% (23/23), done.
Writing objects:100% (47/47), 3.29 KiB | 0 bytes/s, done.
Total (Delta 9), reused 0 (Delta 0)
To Https://github.com/IluckySi/core.git
c143b5a. 99812A9 Master, Master


[Email protected]/d/ilucky/git/core (master)
$ git Checkout Master
Already on ' master '
Your branch is up-to-date with ' origin/master '.


[Email protected]/d/ilucky/git/core (master)

How to use Git on Windows.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.