git-branch

Move existing, uncommitted work to a new branch in Git

吃可爱长大的小学妹 提交于 2019-11-26 00:56:20
问题 I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. How do I move the existing uncommitted changes to a new branch and reset my current one? I want to reset my current branch while preserving existing work on the new feature. 回答1: Use the following: git checkout -b <new-branch> This will leave your current branch as is, create and checkout a new branch and keep all your changes. You can then make a commit with: git add <files>

Change a Git remote HEAD to point to something besides master

为君一笑 提交于 2019-11-26 00:31:55
问题 How do I set a Git remote\'s HEAD reference to point to something besides \"master\"? My project has a policy not to use a \"master\" branch (all branches are to have meaningful names). Furthermore, the canonical master repository is only accessible via ssh://, with no shell access (like GitHub or Unfuddle). My problem is that the remote repository still has a HEAD reference to refs/heads/master, but I need it to point to a different branch. This is causing two problems: When cloning the repo

Why do I need to do `--set-upstream` all the time?

百般思念 提交于 2019-11-26 00:13:27
问题 I create a new branch in Git: git branch my_branch Push it: git push origin my_branch Now say someone made some changes on the server and I want to pull from origin/my_branch . I do: git pull But I get: You asked me to pull without telling me which branch you want to merge with, and \'branch.my_branch.merge\' in your configuration file does not tell me, either. Please specify which branch you want to use on the command line and try again (e.g. \'git pull <repository> <refspec>\'). See git

How to get the current branch name in Git?

醉酒当歌 提交于 2019-11-26 00:10:16
问题 I\'m from a Subversion background and, when I had a branch, I knew what I was working on with \"These working files point to this branch\". But with Git I\'m not sure when I am editing a file in NetBeans or Notepad++, whether it\'s tied to the master or another branch. There\'s no problem with git in bash, it tells me what I\'m doing. 回答1: git branch should show all the local branches of your repo. The starred branch is your current branch. If you want to retrieve only the name of the branch

Why does git perform fast-forward merges by default?

孤者浪人 提交于 2019-11-26 00:09:26
问题 Coming from mercurial, I use branches to organize features. Naturally, I want to see this work-flow in my history as well. I started my new project using git and finished my first feature. When merging the feature, I realized git uses fast-forward, i.e. it applies my changes directly to the master branch if possible and forgets about my branch. So to think into the future: I\'m the only one working on this project. If I use git\'s default approach (fast-forward merging), my history would

Make an existing Git branch track a remote branch?

守給你的承諾、 提交于 2019-11-25 23:57:12
问题 I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch? I know I can just edit the .git/config file, but it seems there should be an easier way. 回答1: Given a branch foo and a remote upstream : As of Git 1.8.0: git branch -u upstream/foo Or, if local branch foo is not the current branch: git branch -u upstream/foo foo Or, if you like to type longer commands, these are equivalent to the above two: git branch --set-upstream-to

How to fetch all Git branches

会有一股神秘感。 提交于 2019-11-25 23:47:32
问题 I cloned a Git repository, which contains about five branches. However, when I do git branch I only see one of them: $ git branch * master I know that I can do git branch -a to see all the branches, but how would I pull all the branches locally so when I do git branch , it shows the following? $ git branch * master * staging * etc... 回答1: You can fetch all branches from all remotes like this: git fetch --all It's basically a power move. fetch updates local copies of remote branches so this is

How do you create a remote Git branch?

丶灬走出姿态 提交于 2019-11-25 23:45:00
问题 I created a local branch which I want to \'push\' upstream. There is a similar question here on Stack Overflow on how to track a newly created remote branch. However, my workflow is slightly different. First I want to create a local branch, and I will only push it upstream when I\'m satisfied and want to share my branch. How would I do that? (my google searches did not seem to come up with anything). How would I tell my colleagues to pull it from the upstream repository? UPDATE With Git 2.0

Deleting a badly named git branch

时光毁灭记忆、已成空白 提交于 2019-11-25 23:38:00
问题 I know this isn\'t strictly a programming question, but it is related to git. I accidentally have created a branch in git called --track (I got the order of options wrong when merging a remote branch) The regular command doesn\'t work: git branch -D \"--track\" I have tried to escape with quotes and backward slashes, however neither work. Any ideas? 回答1: Did you try git branch -D -- --track ? the " -- " is usually the convention for "what follows is not an option, whatever its name" From "The

How do I push a new local branch to a remote Git repository and track it too?

…衆ロ難τιáo~ 提交于 2019-11-25 23:23:48
问题 I want to be able to do the following: Create a local branch based on some other (remote or local) branch (via git branch or git checkout -b ) Push the local branch to the remote repository (publish), but make it trackable so git pull and git push will work immediately. How do I do that? I know about --set-upstream in Git 1.7, but that is a post-creation action. I want to find a way to make a similar change when pushing the branch to the remote repository. 回答1: In Git 1.7.0 and later, you can