Posts with tag git

Copy all upstream branches after forking only main branch

2025-03-24
gitsoftwares-and-tools

Copy all upstream branches after forking only main branchIf you've forked a Git repository but only have the main (or master) branch locally, you can fetch and track other remote branches from the original repository (upstream) into your fork. Here's how:Step 1: Add the Original Repository as upstreamIf you haven't already, add the original repo as a remote named upstream:git remote add upstream https://github.com/original-owner/original-repo.gitVerify remotes:git remote -v # Should show: # origin https://github.com/your-username/forked-repo.git (fetch/push) # upstream https://github.com/original-owner/original-repo.git (fetch)Step 2: Fetch All Branches from UpstreamFetch all branches and their commits from the original repository:git fetch upstreamThis downloads all branches (e.g., feature, dev, etc.) but doesn’t create local copies yet.Step 3: List Available Remote BranchesCheck which branches exist upstream:git branch -r # Shows remote branches (upstream/*)Example output:upstream/main upstream/feature-x upstream/devStep 4: Create Local Branches Tracking UpstreamFor each branch you want to copy (e.g., feature-x), create a local branch that tracks the upstream version:git checkout -b feature-x upstream/feature-xThis:Creates a local branch feature-x.Sets it to track upstream/feature-x.Switches you to the new branch.Repeat for other branches you need.Step 5: Push Branches to Your Fork (Optional)To make these branches available in your fork (on GitHub/GitLab), push them to origin:git push origin feature-xNow they’ll appear in your fork’s remote repository.Alternative: One-Liner to Copy All BranchesTo copy all upstream branches to local and push them to your fork:git fetch upstream for branch in $(git branch -r | grep -vE "HEAD|main"); do git checkout -b ${branch#upstream/} $branch git push origin ${branch#upstream/} doneThis script:Fetches all upstream branches.Loops through each (excluding HEAD and main).Creates local branches and pushes them to your fork.Key NotesTracking Branches: Local branches will track upstream (original repo). To track your fork instead:git branch -u origin/feature-x feature-xAvoid Conflicts: If branches already exist locally, use git checkout -B to reset them.Permissions: Ensure you have push access to your fork (origin).Let me know if you need help with a specific branch or error

Workflow by Gao Tian

2024-04-14
gitsoftwares-and-toolsworkflow

Workflow by Gao Tianref: https://www.bilibili.com/video/BV19e4y1q7JJ@zrx_p4ul on bilibili.com1.git clone // 到本地 2.git checkout -b xxx 切换至新分支xxx (相当于复制了remote的仓库到本地的xxx分支上 3.修改或者添加本地代码(部署在硬盘的源文件上) 4.git diff 查看自己对代码做出的改变 5.git add 上传更新后的代码至暂存区 6.git commit 可以将暂存区里更新后的代码更新到本地git 7.git push origin xxx 将本地的xxxgit分支上传至github上的git ----------------------------------------------------------- (如果在写自己的代码过程中发现远端GitHub上代码出现改变) 1.git checkout main 切换回main分支 2.git pull origin master(main) 将远端修改过的代码再更新到本地 3.git checkout xxx 回到xxx分支 4.git rebase main 我在xxx分支上,先把main移过来,然后根据我的commit来修改成新的内容 (中途可能会出现,rebase conflict -----》手动选择保留哪段代码) 5.git push -f origin xxx 把rebase后并且更新过的代码再push到远端github上 (-f ---》强行) 6.原项目主人采用pull request 中的 squash and merge 合并所有不同的commit ---------------------------------------------------------------------------------------------- 远端完成更新后 1.git branch -d xxx 删除本地的git分支 2.git pull origin master 再把远端的最新代码拉至本

create-a-tag-in-a-github-repository

2024-03-28
gitsoftwares-and-toolstag

ref: https://stackoverflow.com/questions/18216991/create-a-tag-in-a-github-repositoryYou can create tags for GitHub by either using:the Git command line, orGitHub's web interface.Creating tags from the command lineTo create a tag on your current branch, run this:git tag <tagname>If you want to include a description with your tag, add -a to create an annotated tag:git tag <tagname> -aThis will create a local tag with the current state of the branch you are on. When pushing to your remote repo, tags are NOT included by default. You will need to explicitly say that you want to push your tags to your remote repo:git push origin --tagsFrom the official Linux Kernel Git documentation for git push:--tagsAll refs under refs/tags are pushed, in addition to refspecs explicitly listed on the command line.Or if you just want to push a single tag:git push origin <tag>See also my answer to https://stackoverflow.com/questions/5195859/push-a-tag-to-a-remote-repository-using-git/23217431#23217431 for more details about that syntax above.Creating tags through GitHub's web interfaceYou can find GitHub's instructions for this at their Creating Releases help page. Here is a summary:Click the releases link on our repository page,Screenshot 1Click on Create a new release or Draft a new release,Screenshot 2Fill out the form fields, then click Publish release at the bottom,Screenshot 3 Screenshot 4After you create your tag on GitHub, you might want to fetch it into your local repository too: git fetchNow next time, you may want to create one more tag within the same release from website. For that follow these steps:Go to release tabClick on edit button for the releaseProvide name of the new tag ABC_DEF_V_5_3_T_2 and hit tabAfter hitting tab, UI will show this message: Excellent! This tag will be created from the target when you publish this release. Also UI will provide an option to select the branch/commitSelect branch or commitCheck "This is a pre-release" checkbox for qa tag and uncheck it if the tag is created for Prod tag.After that click on "Update Release"This will create a new Tag within the existing Release

git-branch

2024-03-28
branchgitsoftwares-and-tools

git branchMain Git command for working with branches. More information: https://git-scm.com/docs/git-branch.List all branches (local and remote; the current branch is highlighted by *): git branch --allList which branches include a specific Git commit in their history: git branch --all --contains commit_hashShow the name of the current branch: git branch --show-currentCreate new branch based on the current commit: git branch branch_nameCreate new branch based on a specific commit: git branch branch_name commit_hashRename a branch (must not have it checked out to do this): git branch -m old_branch_name new_branch_nameDelete a local branch (must not have it checked out to do this): git branch -d branch_nameDelete a remote branch: git push remote_name --delete remote_branch_nam

need-to-specify-how-to-reconcile-divergent-branches-when-git-pull

2024-03-28
gitpullsoftwares-and-tools

Error message ! [rejected] main -> main (non-fast-forward) error: failed to push some refs to 'github.com:julyfun/mfa.fish.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.orhint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation.First CheckCheck if you have tried git pull.Sol 1Use github desktop, just pull and no problem occurs.Sol 2git config pull.rebase falseThat's what github desktop does

aliyun-git-commit-message

2024-01-15
gitsoftwares-and-tools

https://developer.aliyun.com/article/770277commit message格式<type>(<scope>): <subject>type(必须)用于说明git commit的类别,只允许使用下面的标识。feat:新功能(feature)。fix/to:修复bug,可以是QA发现的BUG,也可以是研发自己发现的BUG。fix:产生diff并自动修复此问题。适合于一次提交直接修复问题 to:只产生diff不自动修复此问题。适合于多次提交。最终修复问题提交时使用fix docs:文档(documentation)。style:格式(不影响代码运行的变动)。refactor:重构(即不是新增功能,也不是修改bug的代码变动)。perf:优化相关,比如提升性能、体验。test:增加测试。chore:构建过程或辅助工具的变动。revert:回滚到上一个版本。merge:代码合并。sync:同步主线或分支的Bug。scope(可选)scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。例如在Angular,可以是location,browser,compile,compile,rootScope, ngHref,ngClick,ngView等。如果你的修改影响了不止一个scope,你可以使用*代替。subject(必须)subject是commit目的的简短描述,不超过50个字符。建议使用中文(感觉中国人用中文描述问题能更清楚一些)。结尾不加句号或其他标点符号。根据以上规范git commit message将是如下的格式:fix(DAO):用户查询缺少username属性feat(Controller):用户查询接口开发以上就是我们梳理的git commit规范,那么我们这样规范git commit到底有哪些好处呢?便于程序员对提交历史进行追溯,了解发生了什么情况。一旦约束了commit message,意味着我们将慎重的进行每一次提交,不能再一股脑的把各种各样的改动都放在一个git commit里面,这样一来整个代码改动的历史也将更加清晰。格式化的commit message才可以用于自动化输出Change log

No more posts to load.