[英]How can I make sure I am running the latest version of the code from GitHub
I am fairly new to git and am a bit confused as to how to set up my workflow to work in the most convenient way possible.我对 git 相当陌生,对于如何设置我的工作流程以尽可能最方便的方式工作有点困惑。
I am working on my laptop (running OSX) and our much beefier server (running CentOS) through ssh, where I try and run time consuming tests for my Python code.我正在通过 ssh 在我的笔记本电脑(运行 OSX)和我们更强大的服务器(运行 CentOS)上工作,在那里我尝试为我的 Python 代码运行耗时的测试。 Doing this for a few months I quickly realised that I was having parallel but separate lines of development since the folder structure is quite different.这样做了几个月,我很快意识到我有并行但独立的开发线,因为文件夹结构完全不同。
I have thus taken the time to set up a github repo and cloned it into my laptop.因此,我花时间设置了一个 github 存储库并将其克隆到我的笔记本电脑中。 Then I diffed the python files pairwise (server version vs laptop version) manually merged the differences and pushed the files up to Github.然后我将 python 文件成对比较(服务器版本与笔记本电脑版本)手动合并差异并将文件推送到 Github。 Lastly I cloned the repo on the server.最后,我在服务器上克隆了 repo。 Now I have the same version on all three places which is great.现在我在所有三个地方都有相同的版本,这很棒。
In the future, I would like to avoid the divergence between the different platforms.将来,我想避免不同平台之间的差异。 Ideally I would like to automatically sync the local repo with Github every time I log in (should in theory be possible to do in .bashrc?), and log out, of the server.理想情况下,我希望每次登录时自动将本地存储库与 Github 同步(理论上应该可以在 .bashrc 中进行?),然后注销服务器。 Essentially I am trying to avoid the chance that I forget manually syncing between the different machines.本质上,我试图避免忘记在不同机器之间手动同步的机会。
How can I achieve this?我怎样才能做到这一点? Are there any potential pitfalls to this strategy?这种策略有什么潜在的缺陷吗?
For git itself, there is no such hooks or settings to automatically sync local repo with remote repo.对于 git 本身,没有这样的钩子或设置来自动将本地仓库与远程仓库同步。
The work around is schedule to run a script to sync local repo with remote repo .解决方法是安排运行脚本以将本地 repo 与远程 repo 同步。
The sync script example (sync master
branch) as below:同步脚本示例(同步master
分支)如下:
#!/bin/sh
git fetch
flag=0
ahead=$(git log origin/master..master --oneline)
if [[ -z "${ahead// }" ]]; then
echo "Local repo has no commits un-pushed"
else
{
flag=1
echo "local master branch is ahead of origin/master $flag"
}
fi
behind=$(git log master..origin/master --oneline)
if [[ -z "${behind// }" ]]; then
{
if [ $flag == 0 ]; then
echo "already sync"
else
git push
fi
}
else
{
if [ $flag == 0 ]; then
git pull origin master
else
{
git pull origin master --rebase
git push
}
fi
}
fi
echo "Now the local repo is aync eith remote repo"
To schedule runs the scripts, you can refer:要安排运行脚本,您可以参考:
schedule running a bash shell script in windows 计划在 Windows 中运行 bash shell 脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.