GitHub使用方法

以下内容都是全英文的,对githu的使用作了详细的介绍。都是比较简单地词汇,阅读后相信你会对github的工作方式,基本操作很了解了。当然,有可能看完后你会跟我一样觉得,还不如git --help命令来得直接。

Git is a distributed version control system

To initialize a Git repository in current directory, type the following command:    git init

The current directory now has an empty repository in /.git/. The repository is a hidden directory where Git operates.

to see what the current state of our project is:    git status

if terminate prompt "untracked"? That means Git sees that file is a new file.

To tell Git to start tracking changes made to octocat.txt, we first need to add it to the staging area by using :    git add filename

after,The files listed here are in the Staging Area, and they are not in our repository yet. We could add or remove files from the stage before we store them in the repository.

checking for changes:    git status       ,to see where we stand

To store our staged changes we run the commit command with a message describing what we‘ve changed:      
 git commit -m “message descriptionxxxx"

We also can use wildcards if you want to add many files of the same type.:         git add ‘*.txt’

Think of Git‘s log as a journal that remembers all the changes we‘ve committed so far, in the order we committed them:       
 git log

created a new empty GitHub repositor, This command takes a remote name and a repository URL:    git remote add origin https://github.com/try-git/try_git.git

(git remote add xxremotename URLname)

The push command tells Git where to put our commits when we‘re ready,The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what
to do. Go ahead and push it!:        git push -u origin master

We can check for changes on our GitHub repository and pull down any new changes by running:      
 git pull origin master

take a look at what is different from our last commit by using the git diff command.

In this case we want the diff of our most recent commit, which we can refer to using the HEAD pointer:      
 git diff HEAD

Using ‘git diff‘ gives you a good overview of changes you have made and lets you add files or directories one at a time and commit them separately.

Let‘s use git add to stage octofamily/octodog.txt:    git add octofamily/octodog.txt

to see the changes you just staged:        git diff —staged

unstage files by using the git reset command.:      
 git reset octofamily/octodog.txt

Files can be changed back to how they were at the last commit by using the command:         git checkout -- <target>.

When developers are working on a feature or bug they‘ll often create a copy (aka. branch) of their code they can make separate commits to. Then when they‘re done they can merge this branch back into their main master branch.

et‘s create a branch called clean_up:        git branch clean_up

Switching Branches--You can switch branches using the git checkout <branch> command:        git checkout clean_up

by using the git rm command which will not only remove the actual files from disk, but will also stage the removal of the files for us.

Commiting Branch Changes---git commit -m "Remove all the cats”

Preparing to Merge------Switch to master branch :    git checkout master,     merge your changes from the clean_up branch into the master branch:  
 git merge clean_up

Delete branch ---You can use git branch -d <branch name> to delete a branch.:        git branch -d clean_up

Staging Area:

A place where we can group files together before we "commit" them to Git.Remember, staged files are files we have told git that are ready to be committed.

Commit A "commit" is a snapshot of our repository. This way if we ever need to look back at the changes we‘ve made (or if someone else does), we will see a nice timeline of all changes.

Wildcards:

We need quotes so that Git will receive the wildcard before our shell can interfere with it. Without quotes our shell will only execute the wildcard search within the current directory. Git will receive the list of files the shell found instead of the wildcard
and it will not be able to add the files inside of the child directory.

Check all the things!

When using wildcards you want to be extra careful when doing commits. Make sure to check what files and folders are staged by using git status before you do the actual commit. This way you can be sure you‘re committing only the things you want.

More useful logs:

Use ‘git log --summary‘ to see more information for each commit. You can see where new files were added for the first time or where files were deleted. It‘s a good overview of what‘s going on in the project.

git remote:

Git doesn‘t care what you name your remotes, but it‘s typical to name your main one origin.

Cool Stuff:

When you start to get the hang of git you can do some really cool things with hooks when you push.For example, you can upload directly to a webserver whenever you push to your master remote instead of having to upload your site with an ftp client.

git stash:

Sometimes when you go to pull you may have changes you don‘t want to commit just yet. One option you have, other than commiting, is to stash the changes.Use the command ‘git stash‘ to stash your changes, and ‘git stash apply‘ to re-apply your changes after
your pull.

HEAD

The HEAD is a pointer that holds your position within all your different commits. By default HEAD points to your most recent commit, so it can be used as a quick way to reference that commit without having to look up the SHA.

Branching:

Branches are what naturally happens when you want to work on multiple features at the same time. You wouldn‘t want to end up with a master branch which has Feature A half done and Feature B half done.

Rather you‘d separate the code base into two "snapshots" (branches) and work on and commit to them separately. As soon as one was ready, you might merge this branch back into the master branch and push it to the remote server.

Remove all the things!Removing one file is great and all, but what if you want to remove an entire folder? You can use the recursive option on git rm:

git rm -r folder_of_cats

This will recursively remove all folders and files from the given directory.

The ‘-a‘ option

If you happen to delete a file without using ‘git rm‘ you‘ll find that you still have to ‘git rm‘ the deleted files from the working tree. You can save this step by using the ‘-a‘ option on ‘git commit‘, which auto removes deleted files with the commit.

git commit -am "Delete stuff”

Pull Requests

If you‘re hosting your repo on GitHub, you can do something called a pull request.

A pull request allows the boss of the project to look through your changes and make comments before deciding to merge in the change. It‘s a really great feature that is used all the time for remote workers and open-source projects.

Merge Conflicts

Merge Conflicts can occur when changes are made to a file at the same time. A lot of people get really scared when a conflict happens, but fear not! They aren‘t that scary, you just need to decide which code to keep.

Force delete

What if you have been working on a feature branch and you decide you really don‘t want this feature anymore? You might decide to delete the branch since you‘re scrapping the idea. You‘ll notice that git branch -d bad_feature doesn‘t work. This is because -d
won‘t let you delete something that hasn‘t been merged.

You can either add the --force (-f) option or use -D which combines -d -f together into one command.

时间: 2024-07-28 18:18:51

GitHub使用方法的相关文章

Linux下Git和GitHub使用方法总结 (码云)

初学先记住这几条,其他慢慢研究. 下面讲如何用码云完成一个项目的提交, 我的步骤 https://git.oschina.net/phpervip/qianzhu(此例:一个企业模板): 先在码云上注册一个帐号. 然后新建项目,就有一个git地址. 本地进入你的项目目录. 初始化项目->建远程连接->获取项目->添加版本->版本提交->远程提交 git init git remote add origin https://git.oschina.net/phpervip/qi

Linux下Git和GitHub使用方法总结

来源:Linux下Git和GitHub使用方法总结 1 Linux下Git和GitHub环境的搭建 第一步: 安装Git,使用命令 “sudo apt-get install git” 第二步: 到GitHub上创建GitHub帐号 第三步: 生成ssh key,使用命令 “ssh-keygen -t rsa -C "[email protected]"”,your_email是你的email 第四步: 回到github,进入Account Settings,左边选择SSH Keys,

【转载】关于初学者上传文件到github的方法

关于初学者上传文件到github的方法 分类: GitHub2013-08-30 00:49 11821人阅读 评论(3) 收藏 举报 说来也惭愧,我是最近开始用github,小白一个,昨天研究了一个下午.终于可以上传了,所以今天写点,一来分享是自己的一些经验,二来也是做个记录,万一哪天又不记得了:) 废话不多说,直接来,这次主要介绍的是windows下的安装和使用. [第一步]建立先仓库 第一步的话看一般的提示就知道了,在github新建一个repository(谷歌可以解决),都是可视化的界

Git系列三之在线GitHub使用方法

代码托管地址:https://github.com 一.认证方式 1.https方式:不需要认证 [[email protected] demo]# git clone https://github.com/nulige/Bastion-of-machine.git Initialized empty Git repository in /root/demo/Bastion-of-machine/.git/ warning: You appear to have cloned an empty

史上最全github使用方法:github入门到精通--备用

[初识Github] 首先让我们大家一起喊一句“Hello Github”.YEAH!就是这样. Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前,包括Rubinius和Merb在内的很多知名项目都使用了Git.Git同样可以被诸如Capistrano和Vlad the Deployer这样的部署工具所使用.同样,eoe.cn客户端的源码也托管在github上. Gi

【Github教程】史上最全github使用方法:github入门到精通(转自eoeandroid.com)

本文来源:http://www.eoeandroid.com/thread-274556-1-1.html 另附经典教程网址 :http://wuyuans.com/2012/05/github-simple-tutorial/ Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前,包括Rubinius和Merb在内的很多知名项目都使用了Git.Git同样可以被诸如Cap

【Github教程】史上最全github使用方法:github入门到精通

[初识Github]首先让我们大家一起喊一句"Hello Github".YEAH!就是这样. Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前,包括Rubinius和Merb在内的很多知名项目都使用了Git.Git同样可以被诸如Capistrano和Vlad the Deployer这样的部署工具所使用.同样,eoe.cn客户端的源码也托管在github上

史上最全github使用方法:github入门到精通

GitHub详细教程 Table of Contents 1 Git详细教程 1.1 Git简介 1.1.1 Git是何方神圣? 1.1.2 重要的术语 1.1.3 索引 1.2 Git安装 1.3 Git配置 1.3.1 用户信息 1.3.2 高亮显示 1.3.3 忽略特定的文件 1.3.4 使用.gitkeep来追踪空的文件夹 1.4 开始操作Git 1.4.1 创建内容 1.4.2 创建仓库.添加文件和提交更改 1.4.3 diff命令与commit更改 1.4.4 Status, Dif

【Mood 16 】史上最全github使用方法:github入门到精通

[初识Github] 首先让我们大家一起喊一句“Hello Github”.YEAH!就是这样. Git 是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前,包括 Rubinius和Merb在内的很多知名项目都使用了Git.Git同样可以被诸如Capistrano和Vlad the Deployer这样的部署工具所使用.同样,eoe.cn客户端的源码也托管在github上.