Git的一些操作

2016-08-23  本文已影响0人  怎么吃都不胖丶

Git的一些操作

流程例子

新建说明文件

touch README.md

在当前项目目录中生成本地git管理,并建立一个隐藏的.git目录

git init

添加当前目录中的所有文件到索引

git add .

提交到本地源码库,并附加描述

git commit -m 'commit description'

添加到远程目录

git remote add origin https://github.com/username/
project.git

把本地源码库push到github名为branchname的分支中

git push -u origin branch_name

git add .
git commit -m 'update description'
git push -u origin branch_name

git clone htts:github.com/username/project.git
git checkout branch_name
git pull

在branch_name分支上执行以下代码

git rebase master
git checkout master
git merge branch_name
git push

常用命令

git config --global user.name 'username'
git config --global user.email 'usereamil'
git init
touch README.md

git add READEME.md
git commit -m 'first commit'
git remote add origin https://github.com/username/project.git

fatal: remote origin already exists

git remote rm origin
git push -u origin master
git add
git commit -m 'first commit'
git push -u origin master

error: failed to push some refs to...

git pull --rebase origin master

Tips: pull = fetch + merge

git push -u origin master
ssh-keygen -C 'email@address.com' -t rsa
git clone https://github.com/username/project.git
git branch branch_name
git checkout branch_name
git push origin branch_name
git branch -d branch_name
git push origin :branch_name
git push origin master:branch_name
git branch -r

添加 .gitignore 文件,并在文件中添加例外规则即可,规则说明如下:

忽略所有目录中的 .idea 目录的全部内容,不管是在根目录还是子目录下的 idea 都会被忽略

.idea/*

忽略根目录中的 idea

/.idea/*

跟踪 .gitignore 文件
忽略全部内容,但是不忽略 .gitignore 文件

!.gitignore

清空暂存区

git rm -r --cached .

2016.8.23 初次接触github做的一些随笔

上一篇 下一篇

猜你喜欢

热点阅读