简体   繁体   English

如何确保我运行的是来自 GitHub 的最新版本的代码

[英]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 脚本

Running .sh every 5 minutes 每 5 分钟运行一次 .sh

You can also related issue here .您也可以在此处相关问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我在我的机器上运行不同版本的 Ruby,如何测试从 GitHub 克隆的某人的 Rails 应用程序? - How can I test someone's Rails app cloned from GitHub if I am running a different version of Ruby on my machine? 如何从 GitHub 获取最新版本的代码? - How to get the latest version of code from GitHub? 如何确定我拥有我的开发分支的最新版本? - How do I make sure I have the latest version of my develop branch? 如何将旧版本存储库中的 zip 文件中的代码与最新版本合并? - How can I merge code in a zip file from an old version of a repository with the latest version? 如何让ZSH使用最新的git版本? - How can i make ZSH use the latest git version? 如何从 github 上的 forked repos 中找到最新的提交? - How can I find the latest commit from forked repos on github? 如何分支我的项目以确保我可以回到原始版本? - How can I branch my project to make sure I can get back to the original version? 使用 Github Desktop,我有一个分支; 如何从 MASTER 获取最新代码? - Using Github Desktop, I have a branch; How do I get LATEST code from MASTER? 如何让 Github 将最新标签显示为默认视图? - How do I make Github show the latest tag as the default view? 如何执行bash命令以检出git分支的最新版本? - How can I make a bash command to check out the latest version of a git branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM