![]() In the same vein you can create git aliases for all snippets from this article. Now you can call it via git command: $ git both-merged This snippet shows only local merged branches, which have appropriate remote merged branches: $ comm -12 <(git branch -merged|awk '')ĭon’t forget to make it executable( chmod 755 git-both-merged), and you can also make a git alias for this script. Usually, it’s simple to remove local and appropriate remote branches at once. Tip for Github usersĪfter the last Github update, Branches page is divided into “Your branches”, “Active branches” and “Stale branches”, and it shows same information as previous commands. This list should be reviewed more thoroughly to avoid losing important commits. Similar snippet for not merged branches: $ for branch in `git branch -r -no-merged | grep -v HEAD` do echo -e `git show -format="%ci %cr %an" $branch | head -n 1` $branch done | sort -r Now, you can delete own remote branches, and ask other authors to clean-up theirs: $ git push origin -delete branch-name This magic snippet provides all required information: $ for branch in `git branch -r -merged | grep -v HEAD` do echo -e `git show -format="%ci %cr %an" $branch | head -n 1` $branch done | sort -r ![]() Would be cool to know last commit date and author. What if this branch is merged, but still used for feature development. Usually, remote repository is a big garbage heap of stale branches, if there is no responsible housekeeping person.Īfter previous git remote prune origin we should have synched list of remote branches.Īt first, we can find branches which are already merged in “master”: $ git checkout masterīut this command does not provide much information. List referenced remote branches: $ git branch -rĬlean-up outdated references: $ git remote prune originĪnd Git automatically prunes all stale references. If some of them is just abandoned stuff that you don’t need anymore, remove it with “-D” option: $ git branch -D old-abandoned-featureĪfter each git pull or git fetch command Git creates references to remote branches in local repository, but doesn’t clean up stale references. Next, decide what to do with not merged branches: $ git branch -no-merged Now, remove all outdated branches with: $ git branch -d old-merged-feature We need to know what branches are already merged in “master” and can be easily removed: $ git checkout master gitconfig Local branchesĪt first, list all local branches: $ git branch Last but not least, you can find me on Twitter.5 Moving stuff into. Now you have the branch on your local repo, and you can test it out locally! □ Running this command will automatically create a branch with the same name in our local repo. You will see in the command line that we have fetched the branches on the upstream repo, including the target branch. git remote -vįetch data from the upstream. We can copy this link by going to the repo on GitHub, clicking the green button with "Code" written on it, and copying the HTTPS link.Ĭheck if the new upstream has now been added. Original-repo-url is the HTTPS URL of the repo that we fork. If we haven't configured a remote that points to the upstream repo, we will get: origin (fetch)Īdd a new remote upstream repo that will be synced with the origin repo. So, I hope you can gain something too from our journey! □ Fetch a branch from the upstream repoĬheck our current configured remote repo for our fork. However, we learned a lot from this accident. In this case, I am the maintainer, and my teammate is the contributor. allows you to fetch all the commits you are looking for in a particular branch. We found out later that what we're doing is an open-source workflow, where we maintain and contribute to a repo. And one of the most important tasks is using git checkout remote branch. My teammate and I started this project with one of us creating a repo and the other forking the repo.īut for collaborating, we could do it differently, which I will cover in another blog post. So, we need to set the origin repo to point to the upstream repo. He then forked this repo, which automatically becomes his origin repo.įor him to fetch a branch - that hasn't been merged to main - from the upstream repo, his origin repo should have access to the upstream. Then we tried to step back and figure things out.įrom my teammate's side, my repo is the upstream repo. We mostly got the error of fatal: couldn't find remote ref. I asked my teammate to fetch this branch and test things out locally before merging it into the main branch.Īfter making sure that we didn't have anything to fetch and merge from the remote repo, and after several attempts, we still couldn't fetch the branch from the remote repo. Then I pushed this branch to the remote repo and created a pull request. Recently, I created a branch to make some changes. I created a repo for the project, and my teammate forked this repo. I am collaborating with a friend to create a project in React.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |