Learn git branchingGit visual teaching project

This is a quick Git tutorial for beginners

These two days I made the Learn Git shoot Main part again. Git branches are very useful for understanding the use of git branches. In addition, the git help documentation and github help documentation are very detailed and should be read carefully.

Use the command to see the answer $show solutionCopy the code

The answers are recorded below

Based on article

Git commands are introduced step by step

1.1 Introduction to Git Commits

Git commit <-m"Submit instructions">
Copy the code

1.2 Branching in the Git

Git branch bugFix git checkout bugFixCopy the code

1.3 Merging in the Git

Git checkout -b bugFix git commit Git checkout master git commitCopy the code

1.4 Rebase;

Rebase essentially takes a series of commit records, "copies" them, and drops them one by one in another location. Git rebase [base] [from] Git rebase [base] [from] Git rebase [base] git rebase [from Git checkout -b bugFix git commit git checkout master git commit git checkout bugFix git rebase masterCopy the code

Senior post

It’s time to introduce Git’s awesome features, so come on!

2. Use ~<num> to move multiple commit records up, such as ~3 eg. HEAD^, which is the last commit master of the current branch ~3 master, which is the third commit before the current branchCopy the code

2.1 the Detach yukio okamoto, ‘HEAD

git checkout C4
Copy the code

2.2 Relative refs (^)

git checkout C4^
Copy the code

Relative Refs #2 (~)

git branch -f master C6
git branch -f bugFix C0
git checkout C1
Copy the code

Their paper Changes in Git

git reset local~1
git checkout pushed
git revert pushed
Copy the code

Moving commit records

Feel free to modify the commit tree

Git cherry-pick... Cherry-pick is the most direct way to copy some commits under the current location (HEAD). Personally, I like cherry-pick very much because it is so simple.Copy the code

3.1 Cherry – pick Intro

git cherry-pick C3 C4 C7
Copy the code

3.2 Interactive Rebase Intro

Git rebase -i master~4 --aboveAll interactive rebase with the -i option provides a visual way to rearrange multiple commits in a custom wayCopy the code

miscellaneous

Git techniques, tricks, and tips

4.1 Grabbing Just 1 Commit

git checkout master
git cherry-pick C4
Copy the code

4.2 Juggling Commits

git rebase -i caption~2 --aboveAll
git commit --amend
git rebase -i caption~2 --aboveAll
git branch -f master caption
Copy the code

4.3 Juggling Commits # 2

git checkout master
git cherry-pick C2
git commit --amend
git cherry-pick C3
Copy the code

4.4 the Git Tags

git tag v0 C1
git tag v1 C2
git checkout C2
Copy the code

4.5 the Git the Describe

git commit
Copy the code

Advanced topics

Only for true warriors!

Rebasing over 9000 times

git rebase master bugFix
git rebase bugFix side
git rebase side another
git rebase another master
Copy the code

5.2 Multiple parents

git branch bugWork master~^2~
Copy the code

5.3 Branch Spaghetti

git checkout one
git cherry-pick C4 C3 C2
git checkout two
git cherry-pick C5 C4 C3 C2
git branch -f three C2
Copy the code

Push & Pull — Git remote repository!

It’s time to share your code and make it social

6.1 the Git Clone

git clone 
Copy the code

6.2 Remote Branch

git commit
git checkout o/master
git commit
Copy the code

6.2 Git Fetch Does not merge remote commits

git fetch
Copy the code

6.3 Git Pull Pull the remote commit for merge

git pull
Copy the code

6.4 Git simulation team commit

git fakeTeamwork 2
git commit 
git pull
Copy the code

6.5 the Git remote5

git clone 
git fakeTeamwork 2
git commit 
git pull
Copy the code

6.5 the Git Push

The code push Git push is responsible for uploading your changes to the designated remote repository and merging your new commit records there. Once Git push is complete, your friends can download your shared work from this remote repository!Copy the code

6.6 Deviant work

When Git push, if there is a new submission in the remote repository, Git will reject the push request and the remote code should be pulled to the local for merging before pushing Gitclone
git fakeTeamwork
git commit 
git pull --rebase
git push
Copy the code

About Origin and its environs — Git Remote Repository Advanced Operations

It would be fun to be a benevolent dictator…

7.1 Push the primary branch

Plan 1: Git fetch git rebase o/master side1 git rebase side1 side2 Git rebase side2 side3 Git rebase side3 master git push git fetch git rebase o/master side1 git cherry-pick C2 C3 C4 C5 C6 C7 git pushCopy the code

7.2 Merging Remote Branches

git checkout master 
git pull
git merge side1
git merge side2
git merge side3
git push
Copy the code

7.3 Remote Tracing


git chekout -b side o/master
git commit
git pull --rebase
git push
Copy the code

7.4 Git Push Parameters

Git push origin < git push originsource>:<destination>
git push origin master
git push origin foo
Copy the code

7.5 Git Push parameter 2

Git push origin < git push originsource>:<destination>
git push origin master^:foo
git push origin foo:master 
Copy the code

7.6 Git Fetch Parameters

git fetch origin master~1:foo
git fetch origin foo:master
git checkout foo
git merge master
Copy the code

7.7 Source without Source

Git push Origin :foo Creates a local branch git fetch Origin :barCopy the code

7.8: Git pull parameters

git pull origin bar:foo
git pull origin master:side
Copy the code

You will see the following message when you have completed all the levels