Skip to main content

GIT Create a Branch and Merging

My previous post was about basic Creating GIT repos server / client
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 
* master
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git branch experiment
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git branch 
  experiment
* 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 experiment 
Switched 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$ ls
readme.txt
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txt 
Bismilla - 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.txt 
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txt 
Bismilla - Now we have updated the File.
Here is the old line.
This is in the Branch - This was added in the Experimental Branch
Hello  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 Branch
 1 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 master 
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txt 
Bismilla - 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.txt
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git merge experiment 
Updating 43a10ac..ea810ac
Fast-forward
 readme.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.txt
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ cat readme.txt 
Bismilla - Now we have updated the File.
Here is the old line.
This is in the Branch - This was added in the Experimental Branch
Hello  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 experiment 
Switched to branch 'experiment'
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git status 
# On branch experiment
nothing to commit (working directory clean)
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git checkout master 
Switched 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.txt 
ahmed@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 MASTER
 1 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 pu
pull   push   
ahmed@ahmed-work-horse:~/ahmed/test.git/test$ git push origin --all
ahmed@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 -> experiment
ahmed@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

Popular posts from this blog

Cloudera Manager - Duplicate entry 'zookeeper' for key 'NAME'.

We had recently built a cluster using cloudera API’s and had all the services running on it with Kerberos enabled. Next we had a requirement to add another kafka cluster to our already exsisting cluster in cloudera manager. Since it is a quick task to get the zookeeper and kafka up and running. We decided to get this done using the cloudera manager instead of the API’s. But we faced the Duplicate entry 'zookeeper' for key 'NAME' issue as described in the bug below. https://issues.cloudera.org/browse/DISTRO-790 I have set up two clusters that share a Cloudera Manger. The first I set up with the API and created the services with capital letter names, e.g., ZOOKEEPER, HDFS, HIVE. Now, I add the second cluster using the Wizard. Add Cluster->Select Hosts->Distribute Parcels->Select base HDFS Cluster install On the next page i get SQL errros telling that the services i want to add already exist. I suspect that the check for existing service names does n

Zabbix History Table Clean Up

Zabbix history table gets really big, and if you are in a situation where you want to clean it up. Then we can do so, using the below steps. Stop zabbix server. Take table backup - just in case. Create a temporary table. Update the temporary table with data required, upto a specific date using epoch . Move old table to a different table name. Move updated (new temporary) table to original table which needs to be cleaned-up. Drop the old table. (Optional) Restart Zabbix Since this is not offical procedure, but it has worked for me so use it at your own risk. Here is another post which will help is reducing the size of history tables - http://zabbixzone.com/zabbix/history-and-trends/ Zabbix Version : Zabbix v2.4 Make sure MySql 5.1 is set with InnoDB as innodb_file_per_table=ON Step 1 Stop the Zabbix server sudo service zabbix-server stop Script. echo "------------------------------------------" echo " 1. Stopping Zabbix Server &quo

Access Filter in SSSD `ldap_access_filter` [SSSD Access denied / Permission denied ]

Access Filter Setup with SSSD ldap_access_filter (string) If using access_provider = ldap , this option is mandatory. It specifies an LDAP search filter criteria that must be met for the user to be granted access on this host. If access_provider = ldap and this option is not set, it will result in all users being denied access. Use access_provider = allow to change this default behaviour. Example: access_provider = ldap ldap_access_filter = memberOf=cn=allowed_user_groups,ou=Groups,dc=example,dc=com Prerequisites yum install sssd Single LDAP Group Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = memberOf=cn=Group Name,ou=Groups,dc=example,dc=com Multiple LDAP Groups Under domain/default in /etc/sssd/sssd.conf add: access_provider = ldap ldap_access_filter = (|(memberOf=cn=System Adminstrators,ou=Groups,dc=example,dc=com)(memberOf=cn=Database Users,ou=Groups,dc=example,dc=com)) ldap_access_filter accepts standa