Bug Branch
Situation: When you are in the process of development suddenly to fix a proposed bug, but now your current branch of the work has not been submitted, but the work is not completed, unable to submit, but also eager to modify the bug
Method: Git provides a stash function, command: git stash
, can be the current work site (the current branch of the work) "storage", and so on after the resumption of the site to continue to work. So the work area is clean.
Next, first determine which branch you want to fix the bug on, assuming that you need to fix it on the master branch, create a temporary branch from master, fix the bug on this temporary branch, fix the commit to the Master branch, complete the merge, and finally delete the temporary branch.
At the end of the branch to switch to the original work, but because the original git stash
hidden work, now this branch of the work area is clean, the original work site to where, you can use the command: git stash list
Check the previous work site, the following is to restore the work site, with the command: git stash apply
, But after recovery, stash content does not delete, you need git stash drop
to use to delete;
There is also a way to git stash pop
directly replace git stash list
and git stash apply
, to express the recovery of the stash content also deleted.
At this point git stash list
, you can't see any stash content anymore.
Note: You can also stash multiple times, restore the time, first use Git stash list to view, and then restore the specified stash, with the command:git stash apply [email protected]{0}
So, when fixing a bug, we fix it by creating a new bug branch, then merging and finally deleting it, and when the work is not done, stash git on the job site, then fix the bug, fix it, then git stash pop and go back to the job site.
Delete a branch that is not merged
Scenario: When creating a branch and modifying a section on this branch has been submitted, but now do not modify this part of the thing, and to delete this branch, but if the direct use of the command git branch -d name
will delete the failure, the hint branch has not been merged, if deleted, will be lost changes, if you want to forcibly delete, Need to use commandgit branch -D name
Method: Forcibly Delete,,, git branch -D name
OK, delete succeeded.
So, if you want to discard a branch that has not been merged, you can forcibly delete it via Git branch-d.
Working mode with multi-person collaboration
Scenario: Suppose the remote warehouse is a repository on GitHub, the default name is origin (the remote warehouse alias), and there are many people working on the warehouse, merge commits can fail if not in a certain regular mode
Method: To push, use git remote
to view remote library information, or to git remote -v
display more detailed information:
The address of origin that can be crawled and pushed is shown above. If you do not have push permissions, you cannot see the address of the push.
Push Branch:
git push origin master
Master is the local branch where you want to specify the push, origin is the remote branch of the remote library, and the push has to follow certain rules:
The Master branch is the main branch, so synchronize with the remote at all times;
The Dev Branch is a development branch, and all members of the team need to work on it, so they need to be synchronized with the remote.
Bug branches are only used to fix bugs locally, there is no need to push remote, unless the boss wants to see how many bugs you have fixed every week;
If the remote library on GitHub does not have a branch feature1, you can git push origin feature1
push the local branch Feature1 directly to the remote repository.
Use the command: git branch -a
to view the branch of a remote repository:
Crawl Branch:
Scenario One: There is now a branch dev on the GitHub remote repository, but there is no local, need to branch the remote Origin's dev to local
Method: Use the command: git checkout -b dev origin/dev
to fetch the dev branch of the remote repository to the ground
Scenario two: To the same branch of Dev, you have made a local change, did not commit, and at this time other people also to your same file has been modified, and has been submitted to the remote repository Dev branch, when you push the push will fail, display the conflict, and then use the git pull
latest submission from origin/ Dev grabs down and then, merges locally, resolves conflicts, pushes back, and discovers git pull
failures.
git pull
The reason for this is that you did not specify a link to the local dev branch with the remote Origin/dev branch, and, as prompted, set up the Dev and Origin/dev links:
$ git branch --set-upstream dev origin/devBranch dev set up to track remote branch dev from origin.
And then again git pull
, success!
Note: When you modify the push, you must first pull, then push
Delete Remote Branch
Scenario: The Gittest repository on GitHub now has remote branch Dev, and now you want to delete it
Use the command:git push origin :dev
On GitHub again, there is no dev branch:
GIT Operations-branch Management (III)