git-branch

Check if a git branch is ahead of another using a script

对着背影说爱祢 提交于 2019-12-07 10:13:37
问题 I have branch1 and branch2 and I want some sort of: git branch1 isahead branch2 That will show if branch1 has commits that branch2 doesn't have (and possibly specify those commits too). I can't check diff cause branch2 is ahead of branch1 (has commits that branch1 doesn't have). Is there a way? I looked through git diff and couldn't find anything 回答1: You can use git log branch2..branch1 If branch1 has no commit ahead of branch2 , output will be empty. You can also use git rev-list --count

Is there a difference between these two ways of moving a branch?

纵饮孤独 提交于 2019-12-07 09:33:30
I was following the interactive LearnGitBranching tutorial and came across two ways of moving around a branch. I want to be sure that I am not missing anything. Is there a difference between: git branch -f master master^ and, supposing HEAD points to master , git reset HEAD^ And, if they do the same thing, why have the reset command at all? Would it mean it's simply a shorthand for git branch -f ? Thank you kindly! torek As genisage noted in a comment , git reset has multiple modes. Ignoring all of the modes and what they do, the answer to the first question is: if HEAD refers to master and

Should we remove a remote Git branch after merging to master?

江枫思渺然 提交于 2019-12-07 08:57:35
问题 I would like to know if it's better to delete your branch after merging to master or if we should continue to work on the same separate branch during all the project. i.e If we are 3 members in the group, each of us create his own branch and works on it during the duration of the project. We all commit in the master branch and pull before we start working on something else. In that way, we know who's working on which branch and we don't get confuse. Thanks. 回答1: So there are tons of

Git remote branch got deleted, how to resync local changes with new branch

眉间皱痕 提交于 2019-12-07 08:13:25
I got a remote branch as develop_1 which I was using. All my local code changes were committed to it but my lead has accidentally deleted that remote branch. I have all those code changes in my local system. Now I want to push all those changes back to that same Git repository in a new remote branch, say develop_2 . How can I create a new branch, sync my local changes and push it to remote? Within your local branch develop_1 you could simply create the new branch: $ git checkout -b develop_2 Push your changes and then to keep your local repo in sync by running: $ git fetch -p The -p is for

How to clone a git repo with all branches and tags from refs/remotes?

北战南征 提交于 2019-12-06 23:47:49
问题 I have a local git repo that I created from an svn repo: $ git svn clone -s svn:... I then created a backup remote and pushed everything to it: $ git remote add backup git@myhost:mybackup.git $ git push --mirror backup Now, when I try to clone from my backup, it is missing all svn tags and branches. $ git clone git@myhost:mybackup.git $ cd mybackup $ git branch -a * master origin remotes/origin/HEAD -> origin/master remotes/origin/master How do I clone the repo with all tags and branches? The

GIT: Adding Local Changes to Non-Current Branch

可紊 提交于 2019-12-06 19:27:05
问题 It usually happens to me that I make some local changes, only to discover that I made it on the wrong branch, so I need to switch branch before committing. The problem is that I cannot switch branch when there are local changes. Is there anyway to do that? Obviously, I can copy the updated files, switch branch, then copy them back, but this doesn't really seem clever! 回答1: You can switch branches while you have local modifications unless your local changes conflict with the difference between

How can I pull from one remote and push to another with git?

为君一笑 提交于 2019-12-06 16:53:38
I have a contributor to my github repository who has a fork and is working on a branch. I want to pull their branch to my own branch and make modifications, but still track theirs. Can I configure git so that while I'm on branch foo , git pull pulls from contributor/foo and git push pushes to origin/foo This is similar to but distinct from the question How can I push to one url and pull from another using one remote? because that question is looking to use the same remote name. VonC You can set the upstream branch to contributor/foo git checkout foo git branch -u foo contributor/foo That

Separate branches or git projects?

非 Y 不嫁゛ 提交于 2019-12-06 16:21:29
I'm introducing Git in our company. I have several applications that all interact together via sockets, and now, it is about to decide whether I should use separate branches for different parts of my application, or separate Git projects. I also want to use tags for revisions; if I use branches, I have to tag like branchnameV1.0, but if I use separate Git projects I could tag like v1.0`. What would be the most conventional method for doing this? Separate Git projects: branches are interesting if you intend to merge common code source. But if your apps are independent (in development, even

git status on master and branches

不羁岁月 提交于 2019-12-06 14:42:38
问题 I made few local changes in the master in git repository and released I have to create a new branch. I created a new branch and committed the changes using git checkout -b changes git add <files> git commit -m "new feature in branch" The name of modified file is "run.pl". Before the new branch, git status on master was On branch master Changes not staged for commit modified run.pl Untracked files build1.pl After the new branch, git status in master is On branch master Untracked files build1

Git: how to change active branch on remote repository?

帅比萌擦擦* 提交于 2019-12-06 14:33:23
I worked on some code on a local branch and then I pushed it to a remote test repository with this command: git push origin fix_vouchers:fix_vouchers I'd like to change the active branch on that remote repository so that the other developers can test this code. Can I do this from my local environment? If the remote repository is just a sharing point, a bare repository, you'd be better off just communicating the branch having the code to the other developers. In a later comment you however imply that the remote repository is a checkout served as a website. You should note that even if you