26/100 Git Manage Branches

The xFusionCorp development team added updates to the project that is maintained under /opt/ecommerce.git repo and cloned under /usr/src/kodekloudrepos/ecommerce. Recently some changes were made on Git server that is hosted on Storage server in Stratos DC.

The DevOps team added some new Git remotes, so we need to update remote on /usr/src/kodekloudrepos/ecommerce repository as per details mentioned below:

1. In /usr/src/kodekloudrepos/ecommerce repo add a new remote dev_ecommerce and point it to /opt/xfusioncorp_ecommerce.git repository.

2. There is a file /tmp/index.html on same server; copy this file to the repo and add/commit to master branch.

3. Finally push master branch to this new remote origin.

ssh natasha@ststor01
sudo su -

cd /usr/src/kodekloudrepos/ecommerce
git branch
* master

#Add the new remote dev_ecommerce and where it should point to - see 1 above
git remote add dev_ecommerce /opt/xfusioncorp_ecommerce.git

#Check it has been created - we will see origin and new dev_ecommerce
git remote
dev_ecommerce
origin

cp /tmp/index.html .
git status <- index.html is shown in red which means it is untracked state -see screenshot below

git add index.html
git status <- see 2nd screenshot, index.html now shown in green

git commit -m "updated index.html"
[master 74ba63e] updated index.html
 1 file changed, 10 insertions(+)
 create mode 100644 index.html

#Push master branch to the new remote origin
git push -u dev_ecommerce
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 242 bytes | 242.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /opt/xfusioncorp_ecommerce.git
 * [new branch]      master -> master
branch 'master' set up to track 'dev_ecommerce/master'.

What is a Git Remote?

Think of it as a bookmark or pointer to another version of your repository, usually stored on a server somewhere like GitHub, GitLab or Bitbucket.
- Your local repo lives on your machine
- A remote is the connection to the repo stored elsewhere
- The default remote is usually named origin when you clone a repo

So when you run the following command it means: send my local master branch to the origin remote repo:

git push origin master

Likewise, the following means bring changes from the master branch of the remote origin into my local repo:

git pull origin master

Think of it like this:

Local Repo = your copy on your laptop/server
Remote Repo = the shared "source of truth" that your whole team pushes/pulls to

Further understanding of git is required - googled a lot to get this to work.