一)更改origin仓库


git clone old-repo.git
cd old-repo
git remote rm origin
git remote add origin new-repo.git(url, should use SSH format url)
git config branch.master.remote origin

git branch --set-upstream-to=origin/master master    //如果设置the requested upstream branch 'origin/master' dose not exist,可先运行一下git pull然后再设置

git push origin master  

//if should pull first and fail to merge, run > git pull origin master --allow-unrelated-histories


二)添加.gitignore文件以忽略某些文件或文件夹

A. Move to the root folder of project

B. Create a file named: .gitignore

C. Edit .gitignore file to ignore what you want

例如:

1)忽略该目录及其子目录中的文件

*.pyc    *.txt等

2)忽略当前目录的直接子目录

/folderName/

3)忽略当前目录的孙目录

*/folderName/


注:

1)强制添加跟踪文件或文件夹

#git add -f fineName/folderName        //添加-f参数

2)检查那条rule忽略了某个文件或文件夹

#git check-ignore -v fineName/folderName

3)如果不希望自己写.gitignore文件,可以在https://github.com/github/gitignore  找到针对不同语言的模板

4).gitignore文件不仅可以加到root文件夹,也可以添加到子文件夹中,只是其作用域仅限该子文件夹及其子孙文件夹


三)Tag管理

常用命令:


在Git,所有的tag都跟特定的commit绑定在一起,并且同一个commit可以绑定多个tag。
git tag tagName        //To bundle a tag with current HEAD commit
git tag tagName ididid          //To bundle a tag with particular commit
git tag -a tagName -m "extra info about tag" ididid         // "-a" to indicate tagName, "-m" to indicate explanation info
git show tagName       //To check the particular tag
git tag        //To list all the tags

git tag -d tagName     //To delete a tag which can be bundled with HEAD or not
git push origin tagName      //To push a tag to remote repo
git push origin --tags       //To push all local tags to remote repo in batch

注:

1)添加tag或者删除tag:git status命令检查不到对tag的增减;git push也不会自动的推送新增的tag,但git clone时是可以clone下来tag的;

2)如果要删除已经push到远程库的tag,则需运行以下命令:

# git tag -d tagName        //First, delete in local

# git push origin :refs/tags/tagName           //Delete from remote repo