git-branch

How to find all refs that contain a commit in their history in git

不打扰是莪最后的温柔 提交于 2019-12-04 08:37:42
Lets assume you have the following structure in git A <-- refs/heads/somebranch | B | \ C D <-- refs/tags/TAG1 | | E F | | \ G H I <-- refs/heads/branch1 | J <-- refs/heads/master Now I want to find all refs that contain commit B in their history. So it would be nice if I could do $ git refs --contains B refs/tags/TAG1 refs/heads/branch1 refs/heads/master I took a look at the git decumentation and found git branch -a --contains <commit_id> which lists all branches that contain a commit_id . $ git branch -a --contains 4af9822 master remotes/origin/someBranch ... and I found the command git tag

Switch to another branch without changing the workspace files

徘徊边缘 提交于 2019-12-04 07:39:08
问题 I cloned a git repository from GitHub, made some changes and some commits; I made quite a lot and all are quite dirty, so they're not suitable for a pull request. Now I created the branch cleanchanges from origin/master , so it's clean, and I want to commit my changes there as one commit with a nice commit comment. When I am on the local master, I want to switch to my cleanchanges but without changing the files. And then I'm able to commit. How can I switch branches without changing files? I

How do I make a branch point at a specific commit?

依然范特西╮ 提交于 2019-12-04 07:23:57
问题 In Git, I understand that a branch is a pointer to a commit. How do I make a specific branch point to a specific commit? Say I want to make master point at 1258f0d0aae... , how do I do that? 回答1: You can make master point at 1258f0d0aae this way: git checkout master git reset --hard 1258f0d0aae But you have to be careful about doing this. It may well rewrite the history of that branch. That would create problems if you have published it and other people are working on the branch. Also, the

Rename a Git branch locally and remotely? [duplicate]

一曲冷凌霜 提交于 2019-12-04 07:22:06
问题 This question already has answers here : Rename master branch for both local and remote Git repositories (15 answers) Closed 3 years ago . Is there a way to rename a Git branch locally and push it to the remote branch, even if there are already many commits pushed to the remote branch? Or, is it necessary to create a new local branch, delete the old local branch, and then repeat the operation on the remote repository? 回答1: Yes, the feature move exists to rename the branch locally git branch -

How do I fetch a branch on someone else's fork on GitHub? [duplicate]

风格不统一 提交于 2019-12-04 07:21:21
问题 This question already has answers here : How to pull remote branch from somebody else's repo (6 answers) Closed 3 years ago . I've forked from a repo on GitHub. I want to get the code from a branch on another user's fork. Must I clone this user's whole repo to a separate local repo or can I do something like git checkout link_to_the_other_users_branch ? 回答1: $ git remote add theirusername git@github.com:theirusername/reponame.git $ git fetch theirusername $ git checkout -b

Change a branch name in a Git repo

牧云@^-^@ 提交于 2019-12-04 07:21:03
问题 How do I rename an existing branch in a Git repo? I want the current branch to have a new name. 回答1: Assuming you're currently on the branch you want to rename: git branch -m newname This is documented in the manual for git-branch , which you can view using man git-branch or git help branch Specifically, the command is git branch (-m | -M) [<oldbranch>] <newbranch> where the parameters are: <oldbranch> The name of an existing branch to rename. <newbranch> The new name for an existing branch.

Error on branch creation: “warning: refname 'master' is ambiguous.”

人盡茶涼 提交于 2019-12-04 05:46:29
I've had simple project being managed in a Git repository. To date I haven't intentionally created any branches, but when I tried to create my first today using $ git branch mybranch I see this error: warning: refname 'master' is ambiguous. fatal: Ambiguous object name: 'master'. Digging deeper: $ git branch -a * master remotes/master/HEAD -> master/master remotes/master/master Is this normal to see in Git? Have I cloned my repository incorrectly? What is the best way to resolve this problem? It seems it's ambiguous because your remote name and branch name are both master . You can try

SSH and Git Clone

痞子三分冷 提交于 2019-12-04 05:22:43
问题 Is it possible to ssh to a remote server and trigger a git clone. ie I need to ssh to server A, create a folder /tmp/A and clone a repository with all its contents on A. The ssh keys of the remote servers are configured to connect to git. ssh root@Server git init git clone gitproject. This doesn't work. Any help is appreciated. I feel the script steps are run asynchronously and thus the clone fails with .git not found. 回答1: You said: "I feel the script steps are run asynchronously" , this

Git branching / rebasing good practices

时光毁灭记忆、已成空白 提交于 2019-12-04 03:47:57
I have a following scenario: 3 branches: - Master - MyBranch branched off Master for the purpose of developing a new feature of the system - MyBranchLocal branched off MyBranch as my local copy of the branch MyBranch is being rebased against and pushed to by other developers (who are working on the same feature as I am). As the owner of the MyBranch branch I want to keep it in sync with Master by rebasing. I also need to merge the changes I make to MyBranchLocal with MyBranch. What is a good way to do that? Couple of possible scenarios I tried so far: I. 1. Commit change to MyBranchLocal 2.

git - create local branch from existing remote branch

时光怂恿深爱的人放手 提交于 2019-12-04 03:46:34
I want to create a branch from an existing remote branch (let's say remote-A) and then commit the changes to repo. I have used the below commands to create a local branch from the existing remote-A $git checkout remote-A git branch master * remote-A Now I have created local-B from Remote A using the below commands git branch local-B git checkout local-B How do I make sure the changes I have on local-B are on top of remote-A so that when I push local-B to the remote repo, the changes are on top of remote-A? you want to create branch on base of remote-A, make changes on it and then push them on