GIT/GIT HUB- Branches

Git Branch -

It is used to create another line of development, without impacting original project.

→ Git Branch is a seperate workspace where we can work on a new features or fixes without affecting the main project/ branch.

→ After the development is done in their brances, everyone merges their code at end.

Types of Branches:

→ Main/Master Branch

→ Development Branch

→ Feature Branch

→ Hot Fix Branch

→ Release Branch

Main/Master Branch: It is the main branch, the about to release code is stored in here( on going production code).

Development Branch : It acts as an intermediate between the main and feature branch

It is used to combine all the new features before adding them to the main branch. It will help in testing and development.

Feature Branch : These branches are created to work on a new feature, once it is done, it is merged back to development branch.

Hot fix Branch : Already code is in production and you find an error for fixing we use hot fix branch, hot fix branch are created in main branch.

Release Branch : Used to prepare for new version of release, small fixes and final testing happens here, before merging to main branch. It is created from development branch.

Git Switch - Advanced version of git checkout

used to switch between one branch to another

syn : git switch <name of the branch you want to switch>

git checkout - This is the older version of git switch

git branch - shows the branches in the local repository

git branch -a : shows all the branches including remote repository

→ For fetching the sub-branches to the main branch we use

git pull --all

git fetch --all

git switch -c : It creates new branch and switch to that branch.

git branch -r : shows the remote branches

Branch Creation:

git branch <branch name>

git commit --ammend -m “msg” : used to update the recent committed message.

git merge<branch name we want to merge> : merging one branch to another

→ We need to give pull request(PR), to merge the files from development branch to main branch.

branch deletion-

git branch -d <branch name>

→ git push origin --delete <branch name>

To delete the branch in remote repository.

Tags :

similar to branch, but they are immutable-once the tag is created/committed we can’t do chnages.

Devops are going to create a tag for particular release.

used to mark release version

major.minor.patch

v1.0.0

Types of tags:

→ lighte weight tag

→ annotated tags

git tag

to display all the tags

create a tag:

git tag v1.0.0 → normal tag

git tag -a v1.0.0 -m “msg” → annotated tag

git show<details of tag>

It gives complete details of that tag

To push the tags from local to remote

git push origin --tags

git push origin v1.0.0 → to push particular tag

git deletion

git tag -d < tag name >

git push origin --delete <tag name>

to delete the tag in remote repo

git stash :

git stash

It is going to temporary store our un-committed changes both tracked and untracked files.so that we can go to other branches and work on it and comes to this branch and continueto work on this.

git stash list

to see all the stashes we executed

git stash apply

to unstash the change we commited

git stash pop

it restores(unstashes) , but remove the stash from list

cherry pick :

If we want to merge the files from one branch to another we use merge command to merge all the files,

but we want to merge particular committed file, then we use cherry pick

git cherry pick <commit id of the file we want to merge>

rebase:

It is like a merge

we merge files from one branch to another but, the history is not maintained

git rebase < name of the branch we want to merge>

ssh-keygen -t rsa -b 4096 -c “name”

0
Subscribe to my newsletter

Read articles from Sandhya Kalikiri directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sandhya Kalikiri
Sandhya Kalikiri