git 在本地备份与指定不需要管理文件

git 在本地备份

备份文件夹操作

在本地备份文件夹克隆一个不带工作区的仓库:

哑协议:

git clone --bare <workspace>/.git yourwork.git

git clone --bare file:///<workspace>/.git yourwork.git

工作文件操作

若是没有关联远端仓库,在本地工作文件直接git push会提示添加远端仓库。

$ git push 
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

看到以上信息,按照提示进行添加。

在项目仓库中,将本地仓库与远端备份仓库进行连接:

添加远端仓库:

git clone --bare <workspace>/.git yourwork.git

git remote add <name>  file:///<workspace>/yourwork.git

可使用git remote -v 查看添加的远端仓库。

$ git remote -v 
<yourwork>   file:///<workspace>/<yourwork>.git (fetch)
<yourwork>   file:///<workspace>/<yourwork>.git (push)

git remote 后,将通过git push <yourwork> master 本地上传到远端。

同时可以通过--set-upstream设置一个默认的远端分支。

$ git push adhoc
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

   git push --set-upstream adhoc master

指定不需要管理的文件

在工作目录下建立.gitignore文件:

<yourwork>/#vim .gitignore
<yourwork>/#cat.gitignore
*.o
#文件夹下文件管理
/*.o    
main
原文地址:https://www.cnblogs.com/zhuandshao/p/12072103.html