My previous post was about basic Creating GIT repos server / client
I will keep it simple for now, later on as I learn complex GIT stuff, will post it :)
Commands we will be using.
$ git branch - lists all the branches in the current repos
Branch Merge to Master Repos
Push Data to Remote SERVER Repos.
Before we start you can also get more information about Branching here
Now lets create Branches and Merge new branch to "master" branch.
Later we will push this update to the remote GIT SERVER repos.
[To setup remote server see my previous post]
I will keep it simple for now, later on as I learn complex GIT stuff, will post it :)
Commands we will be using.
$ git branch - lists all the branches in the current repos
$ git branch - creates a new branch.
$ git checkout - moves control the branch.
$ git merge - merges current branch with .
$ git push origin --all - pushes all data to the remote server repos.
Create a Branch
- Lets create branch and lets call it "experiment"
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git branch* masterahmed@ahmed-work-horse:~/ahmed/test.git/test$ git branch experimentahmed@ahmed-work-horse:~/ahmed/test.git/test$ git branchexperiment* master
- Now we have the branch created
- (*) represents that we are currently in the "master" Branch
- Lets move to branch "experiment"
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git checkout experimentSwitched to branch 'experiment'
- Now we are in the branch "experiment"
- Lets change something here.
- Lets change the readme.txt file and then merge it to "master".
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ lsreadme.txtahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txtBismilla - Now we have updated the File.Here is the old line.Hello People !!!
- Above here is the original file information.
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ vim readme.txtahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txtBismilla - Now we have updated the File.Here is the old line.This is in the Branch - This was added in the Experimental BranchHello People !!!-Ahmed
- After changing.
- Now lets check-in this file to branch.
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git status# On branch experiment# Changes not staged for commit:# (use "git add..." to update what will be committed) # (use "git checkout --..." to discard changes in working directory) ## modified: readme.txt#no changes added to commit (use "git add" and/or "git commit -a")ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git commit readme.txt[experiment ea810ac] Updated in Branch1 files changed, 5 insertions(+), 2 deletions(-)
Branch Merge to Master Repos
- Now the file is committed to branch "experiment"
- Lets move to branch "master"
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git checkout masterSwitched to branch 'master'Your branch is ahead of 'origin/master' by 1 commit.ahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txtBismilla - Now we have updated the File.Here is the old line.Hello People !!!
- In "master" we dont see the changes we made in branch "experiment".
- So now we will merge the two branch.
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git diff readme.txtahmed@ahmed-work-horse:~/ahmed/test.git/test$ git merge experimentUpdating 43a10ac..ea810acFast-forwardreadme.txt | 7 +++++--1 files changed, 5 insertions(+), 2 deletions(-)
- In branch "master" - we will merge branch "experiment"
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git diff readme.txtahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txtBismilla - Now we have updated the File.Here is the old line.This is in the Branch - This was added in the Experimental BranchHello People !!!-Ahmed
- Now we see, branch "experiment" changes in the "master" branch.
- When you try to commit you will see that we are 2 commits behind the origin/master.
- origin/master refers to the remote SERVER repository.
- Lets do few more changes to the file and push it to the remote server.
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git commit readme.txt# On branch master# Your branch is ahead of 'origin/master' by 2 commits.#nothing to commit (working directory clean)ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git checkout experimentSwitched to branch 'experiment'ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git status# On branch experimentnothing to commit (working directory clean)ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git checkout masterSwitched to branch 'master'Your branch is ahead of 'origin/master' by 2 commits.ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git status# On branch master# Your branch is ahead of 'origin/master' by 2 commits.#nothing to commit (working directory clean)ahmed@ahmed-work-horse:~/ahmed/test.git/test$ vim readme.txtahmed@ahmed-work-horse:~/ahmed/test.git/test$ git status# On branch master# Your branch is ahead of 'origin/master' by 2 commits.## Changes not staged for commit:# (use "git add..." to update what will be committed) # (use "git checkout --..." to discard changes in working directory) ## modified: readme.txt#no changes added to commit (use "git add" and/or "git commit -a")ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git commit readme.txt[master 6a06d23] Updated in MASTER1 files changed, 1 insertions(+), 1 deletions(-)ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git status# On branch master# Your branch is ahead of 'origin/master' by 3 commits.#nothing to commit (working directory clean)
Push Data to Remote SERVER Repos.
- Now lets push all the updated information to SERVER repos.
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git pupull pushahmed@ahmed-work-horse:~/ahmed/test.git/test$ git push origin --allahmed@172.16.2.15's password:Counting objects: 11, done.Delta compression using up to 2 threads.Compressing objects: 100% (9/9), done.Writing objects: 100% (9/9), 959 bytes, done.Total 9 (delta 2), reused 0 (delta 0)acb77b7..6a06d23 master -> master* [new branch] experiment -> experimentahmed@ahmed-work-horse:~/ahmed/test.git/test$
- Now you can see that the branch "experiment" and "master" is synced with the remote SERVER repos.
- Other users who dont have this update can "pull" from the remote server.
Thats all for today.
Comments
Post a Comment