The previous article introduced Git's local basic operations, if you don't need to collaborate with others, such as writing a book yourself, writing a small program yourself, writing a website, and so on, it's almost enough. but sharing and collaboration is the theme of the free world, and Git is born for it, so try to be a student who loves to share and collaborate. ^_^
The Git repository concept can be understood as a Git managed folder, and Git remote repository can be understood as a Git managed folder that everyone on the server can access with Git. (Forgive my plain English, although the facts must be bigger than this explanation, but I personally feel that it is harmless to understand) and to understand the remote repository, you need to understand the branch, that is, branch, the previous git log command will list a series of commits, that is, saved changes , then you can understand that the commit chain is a branch, a git repository can have multiple branches, and the branches can be merged, you can create a branch in any commit position in the branch, This means that you can make new changes based on the state of any of the commits, without affecting the previous branch, as the tree has many branches, which can grow anywhere and have no effect on other branches. In fact, I want to say that Git uses the structure of the tree to manage commits, each commit is a node, there is a parent node can have child nodes, and each root node to the leaf node path can be understood as a branch . Let's look at the git commands.
Before you practice the next command, you need to follow the Oschina git repository tutorial To configure your personal account
Http://git.oschina.net/oschina/git-osc/wikis/%E5%B8%AE%E5%8A%A9
? Projects git clone https://git.oschina.net/lrhehe/ddup.git cloning into ' ddup ' ... remote:counting objects:74, Done.remo Te:compressing objects:100% (51/51), Done.remote:Total (Delta 7), reused 0 (Delta 0) unpacking objects:100% (74/74), Done. Checking connectivity ... done.
git clone <url> command is to clone a remote git repository locally , and here is a simple personal project under development, just for example.
? Projects CD ddup? Ddup git: (master) Git Statuson Branch Masteryour branch is up-to-date with ' origin/master '. Nothing to commit, working dire Ctory Clean
Go to the file directory, look at the current git state, here you can see the hint on branch master, indicating that the master branch, the next line of the hint is that your branch and Origin/master are synchronized, here origin is the name of the remote repository, Master is the name of the branch, which means that the master branch of the local master branch and the remote repository origin are synchronized. You can use Git branch-vv to see the connections between this local branch and the remote branch.
? Ddup git: (master) git branch-vv* master b6ca9bf [Origin/master] mod:new commit of common, change minsdk to one for HONEYC Omb
This shows that the first 7 bits of the hash value of the current master branch are B6CA9BF and are synchronized with the master branch of the remote repository origin. The synchronous meaning here is that when you pull the remote repository code locally and Git push (which pushes the local repository's code to the remote repository), it is the two corresponding branches of the operation. if you want to develop together, you have added a new file:
? Ddup git: (Master)? Touch iamcoming.txt? Ddup git: (Master)? git Add.? Ddup git: (Master)? Git commit-m "Add:hello" [Master f8962a9] Hello 1 file changed, 0 insertions (+), 0 deletions (-) Create mode 100644 iamcom Ing.txt
Check out git log:
? Ddup git: (master) git log===========commit f8962a956ef0f1811a944c454ac74e4b369d5961author:lrhehe <[email Protected]>date:fri Mar 00:06:48 +0800 Add:hello
Has committed a commit, so now I want to publish to the remote repository, that is, to share to other small partners, I just need git push to
? Ddup git: (master) git pushcounting objects:4, done. Delta compression using up to 4 threads.compressing objects:100% (2/2), done. Writing objects:100% (3/3), Bytes | 0 bytes/s, done. Total 3 (Delta 1), reused 0 (Delta 0) to Https://git.oschina.net/lrhehe/ddup.git B6CA9BF. 011C5A2 Master, Master
So the remote repository is updated, but if you git push is unsuccessful, because I closed the master non-admin push permission, if you succeed, please contact me or sweet potato brother! Because Mater branches are often used to publish stable program code, it is common practice to create a branch locally to develop, when the development is complete and then merged into the Mater, then push to the remote repository for sharing. You can do this:
? Ddup git: (master) git branch test? Ddup git: (master) git branch-a* Master Test remotes/origin/head-Origin/master Remotes/origin/master
Git branch <name> will be able to create a new branch under the current commit, Git branch-a can see all the existing branches, there is a local more than a newly built test, but the "*" flag tells us that we are still under the master branch, Let's start with git checkout to test:
? Ddup git: (master) git branch test? Ddup git: (master) git checkout testswitched to branch ' test '? Ddup git: (test) Git Statuson branch testnothing to commit, working directory clean
git checkout <branch name> can switch to other branch, you can do anything in the new branch,
? Ddup git: (test) Touch ladygaga.nb? Ddup git: (test)? git Add.? Ddup git: (test)? Git commit-m "add:nb Lady Gaga" [Test 6289a5e] ADD:NB Lady Gaga 1 file changed, 0 insertions (+), 0 deletions (-) Create Mode 100644 LADYGAGA.NB
? Ddup git: (test) git log=========commit 6289a5e635a01aa2be943e34c5c5a8d616863befauthor:lrhehe <[email protected] >date:fri Mar 00:20:05 +0800 add:nb Lady gagacommit 011c5a276c0aa47390b7c026af7371a8f9b3b672author:lrhe He <[email Protected]>date:fri Mar 00:06:48 +0800 Add:hello
The new commit follows the previous commit, and we checkout to the master branch to see git log
? Ddup git: (test) git checkout masterswitched to branch ' master ' Your branch are up-to-date with ' origin/master '.? Ddup git: (master) git log=============commit 011c5a276c0aa47390b7c026af7371a8f9b3b672author:lrhehe <[email Protected]>date:fri Mar 00:06:48 +0800 Add:hello
If you are not aware of the previous changes, if you have completed the development of your own branch, then you can use git merge to merge the individual branch changes into the current branch:
? Ddup git: (master) git merge testupdating 011c5a2. 6289a5efast-forward LADYGAGA.NB | 0 1 file changed, 0 insertions (+), 0 deletions (-) Create mode 100644 LADYGAGA.NB
? Ddup git: (master) git log============commit 6289a5e635a01aa2be943e34c5c5a8d616863befauthor:lrhehe <[email Protected]>date:fri Mar 00:20:05 +0800 add:nb Lady gagacommit 011c5a276c0aa47390b7c026af7371a8f9b3b672au Thor:lrhehe <[email Protected]>date:fri Mar 00:06:48 +0800 Add:hello
The instant Master branch merges the changes to the Test branch, and then you can share your modified code with GIT push.
But if you don't have permission to push to master, you can use Git push Origin <branch name> under the personal branch to push the current personal branch to the remote repository origin, The remote repository origin creates a new branch, which can then be combined with the administrator (slightly low) to merge the branches into master. Here is a small example.
? Ddup git: (master) git branch lrhehe? Ddup git: (master) git checkout Lrhehe switched to branch ' Lrhehe '? Ddup git: (lrhehe) Git push origin lrhehetotal 0 (Delta 0), reused 0 (Delta 0) to Https://git.oschina.net/lrhehe/ddup.git * [New branch] Lrhehe-Lrhehe
? Ddup git: (lrhehe) Git branch--set-upstream-to origin/lrhehe branch Lrhehe set up to track remote branch lrhehe from Origi N.? Ddup git: (lrhehe) git branch-vv* lrhehe b6ca9bf [Origin/lrhehe] mod:new commit of common, change minsdk ... master b6ca9 BF [Origin/master] mod:new commit of common, change minsdk ...
As for how to talk to the administrator is casual ~ ^_^
Git uses summary two: GIT's branch and remote repository