How to tag in Git and its use cases.
Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.
- Changes can be tracked easily
- Provides backup
- Central Version Control System, Ex: svn
- Distributed/Decentralized Version Control System, Ex: Git, Bitbucket
Distributed version control system doesn't rely on a central server to store the source files and all its versions.
Git is a distributed source code management (SCM) tool or version control system. and It uses Github to store repositories remotely.
GIT | SVN |
---|---|
Git is a Decentralized Version Control Tool | SVN is a Centralized Version Control Tool |
Git contains the local repo as well as the full history of the whole project on all the developers machines, so if there is a server outage , you can easily do recovery from your team mates local git |
SVN relies only on the central server to store |
Commits can be done offline too | Commits can be done only online |
Git is written in C language, and since its written in C language its very fast and reduces the overhead of runtimes.
SubGit is a tool for migrating SVN to Git. It creates a writable Git mirror of a local or remote Subversion repository and uses both Subversion and Git if you like.
Git pull merges your local repository with remote repository. Git fetch lists the differences between your local repo and remote repo.
Git pull = git fetch + git merge
git branch –merged
The above command lists the branches that have been merged into the current branch.
git branch –no-merged
this command lists the branches that have not been merged.
Before committing a file, it must be formatted and reviewed in an intermediate area known as ‘Staging Area’ or ‘Indexing Area’.
git add <file_name>
git stash
temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on. Stashing is handy if you need to quickly switch context and work on something else, but you're mid-way through a code change and aren't quite ready to commit.
Git stash drop
command is basically used to remove the stashed item. It will basically remove the last added stash item by default, and it can also remove a specific item if you include it as an argument.
example:
If you want to remove any particular stash item from the list of stashed items you can use the below commands: git stash list: It will display the list of stashed items as follows: stash@{0}: WIP on master: 049d080 added the index file stash@{1}: WIP on master: c265351 Revert “added files” stash@{2}: WIP on master: 13d80a5 added number to log.
Git uses our username to associate commits with an identity.
The git config command can be used to change our Git configuration, including your username. Suppose you want to give a username and email id to associate commit with an identity so that you can know who has made a commit.
use: git config –global user.name “Your Name”
- This command will add your username.
git config –global user.email “Your E-mail Address”
This command will add your email id.
To create a repository, you must create a directory for the project if it does not exist, then run command “git init”. By running this command .git directory will be created inside the project directory.
Feature branching This model keeps all the changes for a feature inside of a branch. When the feature branch is fully tested and validated by automated tests, the branch is then merged into master. Task branching In this task branching model each task is implemented on its own branch with the task key included in the branch name. It is quite easy to see which code implements which task, just look for the task key in the branch name. Release branching Once the develop branch has acquired enough features for a release, then we can clone that branch to form a Release branch. Creating this release branch starts the next release cycle, so no new features can be added after this point, only bug fixes, documentation generation, and other release-oriented tasks should go in this branch. Once it’s ready to ship, the release gets merged into master and then tagged with a version number. In addition, it should be merged back into develop branch, which may have progressed since the release was initiated earlier.
There are some steps to follow. • Create a check list • Create a release branch • Bump the version • Merge release branch to master & tag it. • Use a Pull request to merge the release merge • Deploy master to Prod Environment • Merge back into develop & delete release branch • Change log generation • Communicating with stake holders • Grooming the issue tracker
I have to use following command and enter the required message.
Git commit –amend
Follow the steps
- Create Pull request 2.Modify according to the requirement by sitting with developers
- Commit the correct file to the branch
- Merge the current branch with master branch.
We have following command to create tags in git Git tag v0.1
Switch branch or restore working files
Sends the changes to the remote repository
Commits the changes to the HEAD (staging area) commit message: is the description of the changes performed in the code.
git commit --amend
adds the file changes to the staging area
Creates a branch
Fetch the latest history from the remote server and updates the local repo
Joins two or more branches together
Fetch from and integrate with another repository or a local branch (git fetch + git merge)
Process of moving or combining a sequence of commits to a new base commit
To revert a commit that has already been published and made public
clones the git repository and creates a working copy in the local machine
Use the command “amend” to modify the commit message.
git init
: Initializes a new empty local repository
git clone
: Creates a copy of the original repository from Github on local machine.
git fork
: Creates a copy of the original repository on your github account.
git pull
is the same as git fetch
+ git merge
git commit --amend
git diff-tree -r <commitID>
git diff-tree --no-commit-id --name-only -r <hash>
git branch --merged
git branch --no-merged
(Remove only from git tracking not on disk/file system)
git reset <file name>
or add filename to .gitignore