GitHub Workflow

Pull remote branch

  1. Create a new empty folder
  2. Initial
git init
  1. Create remote connection
git remote add origin https://gitee.com/XXXX.git
  1. Fetch remote branch to local
git fetch origin branch_name
  1. Create local branch and swift to this branch
git checkout -b local_branch_name origin/remote_branch_name
  1. Pull
git pull origin remote_branch_name

Push to remote branch

  1. git add .
  2. git commit -m “message”
  3. git pull origin remote_branch_name
  4. git push origin remote_branch_name

Create .gitignore before pushing

  1. touch .gitignore
  2. enter i to edit .gitignore

Example .gitignore for Vue projects:

.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
  1. Press esc to exit editing mode, enter “:wq” to save.

Note that if there are submissions already, we should remove cache before pushing again, or .gitignore would not be working.

git rm -r --cached .
git add . 
git commit -m 'update .gitignore'
git push origin remote_branch_name
### 批量删除GitHub工作流 对于批量删除GitHub上的工作流文件,可以采取脚本化的方式实现自动化操作。由于GitHub的工作流定义通常位于`.github/workflows/`目录下的YAML文件中,通过编程方式访问这些资源并执行删除动作成为可能。 一种方法是利用Python编写一个简单的程序来完成此任务。该程序会调用GitHub API接口获取指定仓库中的所有工作流列表,并允许用户确认要移除哪些项。下面是一个基本的例子: ```python import requests from github import Github def get_workflows(repo_name, token): g = Github(token) repo = g.get_repo(repo_name) workflows = list(repo.get_work_flows()) return [(wf.id, wf.path) for wf in workflows] def delete_workflow(repo_name, workflow_id, token): url = f"https://api.github.com/repos/{repo_name}/actions/workflows/{workflow_id}" headers = { "Authorization": f"token {token}", "Accept": "application/vnd.github.v3+json" } response = requests.delete(url=url, headers=headers) if response.status_code == 204: print(f"Workflow with ID {workflow_id} deleted successfully.") else: print(f"Failed to delete workflow {workflow_id}. Status code: {response.status_code}") if __name__ == "__main__": personal_access_token = 'your_personal_access_token_here' repository = 'owner/repo' # 获取所有工作流的信息 all_workflows = get_workflows(repository, personal_access_token) # 输出每条记录供选择 for idx, (id_, path_) in enumerate(all_workflows): print(f"{idx}: Path={path_}, ID={id_}") selected_indices = input("Enter indices of items you wish to remove separated by spaces:") selections = [int(i.strip()) for i in selected_indices.split()] confirm = input("Are you sure? Type yes/no:") if confirm.lower().strip() != 'yes': exit() for index in selections: id_to_delete = all_workflows[index][0] delete_workflow(repository, id_to_delete, personal_access_token) ``` 上述代码片段展示了如何使用PyGithub库以及requests库与GitHub REST API交互以达到目的[^2]。需要注意的是,在实际应用前应当替换掉示例中的个人访问令牌和个人资料信息,并确保遵循安全最佳实践处理敏感数据。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值