Setting up a local branch

  1. Use the git branch command to see that there is only one master branch in the current directory
  2. Create a branch using the name of Git Branch, and when you have created it, you can see that a new branch 3 has been created locally through Git Branch. Use the Git Checkout branch name to switch to a local branch to start development such as the Git Checkout Test

Merge branches to master

1. After finishing the code, check the status first, and you will find that all the findings are red, indicating git status in the current workspace

2. Add the current branch workspace to git add.3. If you check the status again, you will see that it is green, indicating that you have added git status to the temporary storage area

Git commit -m git commit -m git commit -m git commit -m

5. Check the current branch git branch — you can see the current branch is login

6. “master git checkout” : “master git checkout”

Git merge login git merge login

8. Finally, upload the master branch to the remote master git push origin master

The branch commits to the branch

Git push origin local branch name: name of the remote branch

The remote repository pulls a branch that does not exist locally

Git checkout -b local branch name origin/ remote branch name This will automatically create a new local branch and associate it with the specified remote branch. The pull was unsuccessful. We need to perform git fetch first and then git checkout -b with the local branch name origin/ remote branch name

Multiple branch switch

One of the tips for switching branches is to keep your workspace and staging areas clean when switching branches, and the git stash command is used to do just that.

When we encounter this situation, I cannot submit the local changes, and I don’t want to bring them to the newly switched branch, let alone throw them away directly. I just want to temporarily save them in a place, and then switch back to welcome them after I have switched the branch and corrected the BUG. If you want to save local changes with SVN, you can use patch, and if you want to solve this problem with Git, you can use the Git stash command. The most commonly used are Git Stash Push cache changes and Git Stash Pop restore temporary changes

subsequent

If you do not want to merge the new branch test with the main branch master, but want to upload the files on the new branch to the remote corresponding branch, do the following. The first step is to set up a branch on the remote GitHub that corresponds to the local branch. If I create a new branch locally as test, then I create a new branch on the remote GitHub as test, with the following operation:

1. Open Git tool and enter local repository, such as myProject, since the default branch is master, so first switch to test, Git checkout test

Git push –set-upstream origin test: git push –set-upstream origin test: git push –set-upstream: “test” : “test” : “test” : “test” : “test” : “test” : “test” : “test”

3. If I create a new test file on the local test branch, the file content is “hello world!” Echo “Hello world!” >test.txt

4. Add the new file to the cache. The operation is: git add.

Add the contents of the cache to the local repository by saying: git commit -m “test branch”

6. Commit the contents of the local branch test to a remote GitHub with the operation: git push origin test

Git push –delete origin <branchName> git push –delete origin <branchName>

Note: The first time you create a remote branch, you need to perform step 2. If you want to commit the contents of the local branch to the remote branch, you can simply git push it directly

Finally, if you want to retrieve the contents of the remote test branch to the local test branch, what do you do?

In fact, it is very simple, open the Git tool, enter the local branch warehouse, then Git pull origin test, for example, my local warehouse is in E disk >myGit>Git, the warehouse name is myProject, then my operation is as follows:

CD e:, CD mygit, CD git, CD myproject, git pull origin test (” test “)

The contents of the remote test branch have been fetched to the local test branch.

Similarly, if I want to commit the contents of the local branch test to the remote branch master, then I will do: git push origin master

  

Conclusion:

Git branch: git branch

Git branch git branch git branch git branch

Git branch -d git branch -d

Switch branch to git checkout and create a branch name

Merge branch name git merge merge branch name

Git push –set-upstream origin: git push –set-upstream

Git pull origin test git pull origin test git pull origin test

Git push origin test git push origin test git push origin test

Git push –delete origin <branchName> git push –delete origin <branchName>

Git branch -a git branch -a git branch -a

Git checkout -b branch name: git checkout -b branch name

12. Configure user name and mailbox:

Git config –global user.name

Git config –global user

Relate to a remote repository:

Git remote add origin

Git branch -a: git branch -a: git branch -a: git branch -a: git branch -a: git branch -a: git branch -a: git fetch origin –prune

14. If you are halfway through a branch and you have an urgent bug to fix, but you do not want to make a git commit, you can start with git add. When you commit your current project to Git version control, use Git Stash to temporarily save your current files, and then switch to another branch. After completing the task, cut back to the current branch and perform Git Stash Pop to restore it

The git pull – rebase