github(2)Github Basics and Remote Repositories

本文详细介绍了Git版本控制系统的基本操作,包括本地版本控制、分布式版本控制的概念,以及如何在Windows环境下安装Git。此外,还讲解了如何初始化仓库、提交文件、查看提交历史等基本命令,并提供了远程仓库的操作指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

github(2)Github Basics and Remote Repositories

Chapter 1 Getting Started
1.1. About Version Control
Local Version Control
----> Centralized Version Control System(CVCS, CVS, Subversion, Perforce)
----> Distributed Version Control System (DVCS, Git, Mercurial, Bazaar, Darcs)

1.2. Git Basic
Git does not care about the file differences, but saves all snapshot of all the files.

3 Status of the files
committed ----> modified ---> staged(it is in the commit list)

3 working area
Working directory ----> Staging area -----> git directory(repository)

1.3. Windows Install
http://code.google.com/p/msysgit
>git --version
git version 1.7.9.msysgit.0

user information
>git config --global user.name luohuazju
>git config --global user.email luohuazju@gmail.com

check the configuration file
>git config --list

getting help
>git help <verb>

Chapter 2 Git Basics
2.1 Getting a Git Repository
Initializing a Repository in an Existing Directory
Go to the project's directory and type
>git init
This creates a new subdirectory named .git that contains all of your necessary repository files.
>git add readme.txt
>git commit -m "create repository"
After this, we have a git repository with tracked files.

>git remote add origin git@github.com:luohuazju/magic.git
>git push -u origin master
error message:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Cloning an Existing Repository
>git clone git://github.com/luohuazju/cat.git
or
>git clone git://github.com/luohuazju/cat.git cat

2.2 Recording Changes to the Repository
Checking the Status of Your Files
>git status

Tracking New Files
>git add filename

Staging Modified Files
>git add filename

Ignoring Files
>vi .gitignore
*.[oa] #ignore the files .o or .a
!lib.a #do track lib.a, even though you are ignoring .a files above
build/ #ignore all files in the build/ directory
doc/*.txt #

Viewing Your Staged and Unstaged Changes
Committing Your Changes
>git commit
or
>git commit -m "message"

Removing Files
>git rm filename

Moving Files
>git mv file_from file_to

2.3 Viewing the Commit History
Simple command
>git log
Using a GUI to Visualize History

2.4 Undoing Things
Unstaging a Staged File
>git reset HEAD t2.txt

Unmodifying a Modified File
>git checkout -- filename

2.5. Working with Remotes
You can have several remote servers. You can pushing and pulling data to and from remote repositories when you need to share work.

Showing Your Remotes
>git remote
It lists the shortnames of each remote handle.
>git remote -v
origin git://github.com/luohuazju/cat.git (fetch)
origin git://github.com/luohuazju/cat.git (push)

Adding Remote Repositories
>git remote
>git remote add origin git://github.com/luohuazju/magic.git
>git remote -v
origin git://github.com/luohuazju/magic.git (fetch)
origin git://github.com/luohuazju/magic.git (push)

>git fetch origin

Pushing to Your Remotes
>git push [remote-name] [branch-name]
>git push origin master

There are some error message, so I change the remote like this.
>git remote add origin git@github.com:luohuazju/magic.git
>git push -u origin master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

solution:
Set Up SSH Keys
step1: open Git Bash
>cd ~/.ssh
step2: I already have this directory. Backup and remove existing SSH Keys.
>mkdir key_backup
>cp known_hosts key_backup/
>rm known_hosts
step3: Generate a new SSH key.
>ssh-keygen -t rsa -C "luohuazju@gmail.com"
>start.
I open the directory on win7 and get the key file id_rsa.pub.

step4:Add my SSH Key to GitHub
Account Setting--->SSH Keys ----> Add New SSH key

step5: Test everything out
>ssh -T git@github.com

Everything works fine now.

Inspecting a Remote
>git remote show [remote-name]

Removing and Renaming Remotes
>git remote rename first_name second_name

>git remote rm remote_name

references:
http://progit.org/book/zh/
http://progit.org/book/ch2-1.html
http://progit.org/book/ch2-5.html
http://sillycat.iteye.com/blog/1323263
http://sillycat.iteye.com/blog/1131274
http://sillycat.iteye.com/blog/1074171
http://sillycat.iteye.com/blog/689970
http://help.github.com/ssh-issues/
http://help.github.com/linux-set-up-git/
http://help.github.com/win-set-up-git/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值