Steps To Create A Reppository in Git (19 Files Merged)
Steps To Create A Reppository in Git (19 Files Merged)
git diff
git remote -v
# View existing remotes
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
git remote -v
# Verify new remote URL
# origin https://github.com/user/repo2.git (fetch)
# origin https://github.com/user/repo2.git (push)
#ssh-keygen -t rsa
8. while downloading we will get the merge conflicts in the worked file
9. we need to remove the unwanted correctors and rearrange the file in
whatever structure you want then
10. git add .
11. git commit -m "msg"
12. now push the changes -->git push origin master (or) git push -f
origin master
1. Gitflow:
-------
Gitflow is a popular branching strategy that uses two main branches:
master and develop.
Gitflow is a robust branching strategy that works well for large projects
with long release cycles, but it can be complicated to set up and
maintain. It also requires strict discipline around feature branch
creation and merging.
2. Feature branching:
-----------------
3. Release branching:
-----------------
Release branching is a good option for projects with short release cycles
or when there are specific testing requirements for each release.
However, it can be challenging to manage multiple release branches
simultaneously.
Hotfix Branches:
----------------
In Gitflow, hotfix branches are created from the master branch when a
critical bug needs to be fixed in the production release. Once the hotfix
is complete, it is merged back into the master and develop branches.
This approach is used to quickly fix critical bugs that are found in the
production release. It’s a way to separate the bug-fixing work from the
ongoing development work and keep the master branch stable.
You will start by creating a master branch. This will be the main branch
for production releases.
As the development work progresses, new features and bug fixes are added
to the master branch, and new releases are created.
Let’s say, at some point, a critical bug is found in the production
release. So, a hotfix branch will be created from the master branch.
Let’s call it hotfix1.
The hotfix1 branch is used to fix the bug. This includes coding, testing,
and debugging.
Once the hotfix is complete, it is merged back into the master and
develop branches.
Finally, the hotfix1 branch is deleted
Overall, hotfix branches are used to fix critical bugs that are found in
production quickly, without disrupting the ongoing development work. It
is useful, If you have a long release cycle, you can use hotfix branches
to fix bugs that are found in production
Architecture Overview:
---------------------
The master branch is the main development branch where all new features
are added and tested using feature flags.
When a feature is ready for release, the feature flag is removed, and the
feature is released.
Hotfixes are added directly to the master branch.
In today’s fast-paced software development environment, the ability to
quickly and effectively develop and release software is vital. However,
managing code changes and merging them in a timely and organized manner
can be a challenging task, especially when working with a large team of
software engineers.
Git Flow
GitHub Flow
Trunk Based Development
1. GitFlow:
--------
Git flow is a popular branching strategy that uses a central repository
to maintain different branches for development, releases, and hotfixes.
In Gitflow, there are two main branches: the develop branch and the
master branch. The develop branch is used for ongoing development work,
while the master branch is used for production releases.
Feature Branching:
-----------------
It’s well suited for teams that are working on multiple features at the
same time and want to keep their codebase stable. However, it’s also
important to have a process in place to merge and review the feature
branches before they’re merged into the main branch to avoid conflicts
You will start by creating a develop branch from the master branch. This
will be the main branch for ongoing development work.
Next, you will create a new branch from the develop branch to implement a
new feature. Let’s call it feature1.
Then, you will work on feature1 in the feature branch. This can include
coding, testing, and debugging.
Once feature1 is complete, it is merged back into the develop branch.
This can be done using a pull request.
Repeat steps 2–4 for each new feature that needs to be implemented.
Once all features are complete, the feature branches would be merged back
into the develop branch using a pull request and eventually into the
master when it is ready for release.
Overall, feature branching is a simple strategy that allows for a high
degree of flexibility and parallel development. It’s well suited for
teams that are working on multiple features at the same time and want to
keep their codebase stable.
Release branches:
----------------
It’s a way to separate the ongoing development work from the release
management. It is mainly used to isolate the release management work from
the ongoing development work and keep the master branch stable. This
allows the team to work on new features while also allowing for a stable
release branch for testing and QA.
They will start by creating a develop branch from the master branch. This
will be the main branch for ongoing development work.
As the development work progresses, new features and bug fixes are added
to the develop branch.
When it’s time to release a new version of the software, a release branch
is created from the develop branch. Let’s call it release1.
The release1 branch is used to test and prepare the release. This
includes testing, bug fixing, and finalizing documentation.
Once the release is ready, it is merged into the master branch. This
creates a new production release.
Finally, the release1 branch is deleted, and development continues on the
develop branch.
Overall, release branches are used to isolate the release management work
from the ongoing development work and keep the master branch stable. The
base of a release branch is typically the development branch or the
develop branch, which contains all of the latest features and changes
that have been implemented.
It’s useful when you have a long release cycle, you can use release
branches to keep track of the progress of a release.
Hotfix Branches:
----------------
In Gitflow, hotfix branches are created from the master branch when a
critical bug needs to be fixed in the production release. Once the hotfix
is complete, it is merged back into the master and develop branches.
This approach is used to quickly fix critical bugs that are found in the
production release. It’s a way to separate the bug-fixing work from the
ongoing development work and keep the master branch stable.
2. GitHub Flow:
------------
GitHub Flow is a branching strategy that is similar to Gitflow but it is
simpler, lightweight, and more focused on continuous deployment. It is
designed for smaller teams and projects that require faster release
cycles.
In GitHub Flow, there are two main branches: the master branch and the
feature branch. The master branch is used for production releases, and
all new code is committed to this branch. Feature branches are created
off of the master branch and are used to implement new features.
Once a feature is complete, it is merged back into the master branch and
is immediately deployed to production.
You will start by creating a master branch. This will be the main branch
for production releases.
Next, you will create a feature branch from the master branch. This
branch will be used to implement a new feature. Let’s call it feature1.
Now, you work on feature1 in the feature branch. This can include coding,
testing, and debugging.
Once feature1 is complete, it is merged back into the master branch. This
can be done using a pull request.
The code is immediately deployed to production after being merged into
the master branch.
Finally, the feature branch can be deleted
Overall, GitHub Flow is a simple and effective strategy that is well-
suited for smaller teams and projects that have a need for faster release
cycles. This strategy is focused on continuous deployment, which allows
teams to deploy new features and bug fixes to production as soon as they
are ready
3. Trunk-Based Development:
------------------------
The trunk-based development is a simpler branching model that uses a
single trunk or master branch for all development. New features and bug
fixes are committed directly to the trunk, with no additional branches
required. This strategy is more suitable for smaller projects or teams
that prefer a simpler workflow.
This strategy involves working directly on the main development branch,
with developers/QA’s committing their changes frequently and relying on
automated testing and continuous integration to catch any issue
For Example, If you are working on a software development project and you
want to implement TBD, then you can follow the below steps :
You will start by creating a master branch called trunk or master. This
will be the branch that contains the latest stable version of the
codebase. This branch will be used as the base for all new development
work, and you can merge your code changes into this branch.
Next, you will create a new branch for each change, and make your code
changes on that branch.
Before opening a pull request, make sure you run the tests locally to
ensure that the code changes don’t break the application.
When all the test case passes, you can open a pull request to merge your
changes into the master branch. This triggers the CI pipeline, which
automatically builds and tests the code changes.
Now, other team members should review your code changes and provide
feedback or suggestions. If any issues are found, you can fix them and
push the changes to the branch.
Once the code changes have been reviewed and tested, the pull request is
approved and merged into the main branch. The changes are automatically
deployed to a staging environment for further testing.
By following the above process, you can catch and fix issues early,
before they become a problem. You can also deploy new features and bug
fixes to production more frequently, which allows you to deliver value to
users more quickly.
Feature flags
Using feature flags in TBD, teams can toggle portions of code on or off
for the build process, and deploy only the necessary code in production
environments. This allows teams to deploy new code changes and features
to production while keeping them hidden from users.
Once the code changes have been thoroughly tested and are deemed stable,
the feature flags can be turned on, making the changes available to
users.
A/B testing: allows teams to test new features with a subset of users
before rolling them out to the entire user base.
Gradual rollouts: allows teams to gradually roll out new features to
users, rather than releasing them all at once.
Canary releases: allows teams to test new features with a small subset of
users before releasing them to the entire user base.
Rollbacks: allows teams to quickly rollback a new feature or change if it
causes issues in production.
Using feature flags, you can deploy code changes to production with
confidence, knowing that you can quickly revert or disable any changes
that cause problems. It also allows you to work on multiple features or
bugs in parallel and deploy them independently of each other.
git reset
---------
1.git reset is of three types
-->git soft -- go to staging area
-->git mixed -- go to workspace
-->git Hard -- undo changes in workspace
1.Remove the commits but keep their changes staged--> git reset --soft
HEAD~1 (or) git reset --soft cd767s6(if you want to reset latest commit
give the previos commit id)
2.Remove the commits but keep their changes in the working directory
(unstaged) --> git reset --mixed HEAD~1 or git reset --mixed(default)
3.Remove the commits and remove all their changes from your working
directory --> git reset --hard HEAD~1
4.git reset --hard HEAD~1 (or) git reset --hard HEAD~2 you can change the
numbers depending upon the number of latest commits you want to reset.
5.git reset --soft HEAD~1 (or) git reset --soft HEAD~2 you can change the
numbers depending upon the number of latest commits you want to reset.
git revert
----------
1.when the incorrect changes are pushed into remote repository if we want
to revert changes from remote repository we use git revert
2.copy the commit id of the file which you want to revert --> git revert
cd767s6
3.it shows reverting these file then exit
4.now go to git log you will see the existing commit and aslo you will
see a new extra commit msg called revert "existing commit msg"
5.now push the changes to remote --> git push origin master
6.you will see the incorect changes are reverted in remote repository.
To edit latest commit message in git --> git commit --amend -m "edit
commit message"
------------------------------------vi h
1. to edit the latest commit message --> git commit --amend -m "edited
message"
2. The commit message is edited
3. if you want to edit 3rd commit message in git log --> git rebase -i
HEAD~3
4. now last 3 commit commits will open where you will see the last three
commit messages
-->pick 5td567q "commit message"
-->pick 5td567q "commit message1"
-->pick 5td567q "commit message1"
5. now you will see the commit messages count from last as 1 2 3
6. now in 3rd commit replace pick with reword then save and exit(ctrl+O--
>ENTER-->ctrl+X-->edit message-->ctrl+O-->ENTER-->ctrl+X)
7. now you will see your 3rd commit message which you want to edit. edit
it then save the exit
8. now the changes in the 3rd commit message are edited.
9. to push the edited commit messages --> git push -f origin master
(force push)
1. git squash is used to make multiple commits into one commit
2. if you want to squash the first four commits into one commit we have
to add the previous commit also to give the number of commits needed to
squash
3. to squash the first 4 commits into one --> git rebase -i head~5
4. here in the above command we have given no of commits as 5 to squash
the 4 commits
5. you cannot squash without the previous commit
6. to squash the first four commits into one --> git rebase -i head~5
7. now last 5 commit commits will open there you will see the last five
commit messages in reverser order(git log 4,3,2,1,o) (git rebase
0,1,2,3,4)format.
-->pick 5td567q "commit message"
-->pick 5td567q "commit message1"
-->pick 5td567q "commit message2"
-->pick 5td567q "commit message3"
-->pick 5td567q "commit message4"
8. you can't squash the previous "commit message" line it will throw an
error.
9. now replace pick with squash to fist four lines(from down)
"msg1,msg2,msg3,msg4" then save and exit.
10. now you will see the commits messages edit them all to one commit
message then save and exit.
11. to check the squash status -->git log
12 You will see the multiple commits into one commit.
1. If you are working on a new feature in your project?
2. for that you have created a separate branch(future) for that purpose.
3. if you want to add these changes to the master branch?
4. Then MERGE or REBASE can be helpful
Scenario:
-------
1.a devoloper1 added two commits in master branch m1,m1
2.then he switched to a new branch(future) and added new commits fm3,fm4
3. now devoloper2 in the master branch added another new commit m3,m4
4. if devoloper1 wants to add future branch commits to the master branch
then we use git merge, git rebase
NOTE:(REBASE):
git rebase master
*Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
error: could not apply 586fd52... f1
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git
rebase --abort".
Could not apply 586fd52... f1
now resolve merge conflicts
*vi hello.txt
1
2
<<<<<<< HEAD(delete)
5
6
=======(delete)
3
>>>>>>> 586fd52 (f1)(delete)
~
in above txt line 4 is missing ignore it and resolve conflicts save and
exit
*git status
ERROR
-----
interactive rebase in progress; onto 7d5702c
Last command done (1 command done):
pick 586fd52 f1
Next command to do (1 remaining command):
pick 5c8f937 f2
(use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'feature' on '7d5702c'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: hello.txt
*now
*git add .
*git rebase --continue
*it will open a nano terminal
*try not to change the commit message
save and exit
* if you want to add future branch changes to the master branch without
commit messages in the above scenario then use--> git merge --squash
future
(or)
Rebase
-------
1. It is a two-step process
git checkout feature
git rebase master
git checkout master
git merge feature
2. Rebase clears history of feature branch.
3. Every commit has only one parent and
history is linear.
4. In Rebase, there is no chance of conflicts.
5. We can not aware which changes are
coming from which branch.
6. It is not recommended to use rebase on
public repositories.
cherrypick: picking a specific commit from one branch and applying that
commit to another branch
----------
1. we have two branches master and future
2. in master we have 3 commit files one two three
3. in the future we have 2 commit files four and five
4. I want to merge one of the commits from the future branch to the
master as the other commit needs some changes so we are merging only one
commit
5. in this case we do cherry-pick
6. now stand on master branch -->git checkout master
7. then check commits -->git log --oneline
8. copy the commit-shah(4d5568c) from the future branch which you want to
merge into the master branch
9. now do cherrypick --> git cherry-pick 4d5568c
10. now check the commit using -->git log --oneline
11. you will see the specific commit is merged into the master branch
NOTE: if you pick the latest commit from another branch the other commits
before which are not merged are also picked
till the latest automatically so the merge conflicts occur resolve them
and fix
git ignore: The purpose of git ignore files is to ensure that certain
files untracked by Git remain untracked or ignored.
----------
(or)
git ignore file is used in a git repository to ignore the files and
directories that are unnecessary to the project this will be ignored by
the git once the changes as been committed to the Remote repository.
name: CI
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially
or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
apply commit to master branch (or) create a new branch and commit the
code there
now check actions you can see the created .yml file is build in actions
configure
---------
# Create the runner and start the configuration experience
$ ./config.sh --url https://github.com/swethukrishna/GIT --token
AWLF5VSD2NLPCYKKT3CNWULDIX7SM# Last step, run it!
$ ./run.sh
github will be connected to your instance
sample code
-----------
on:
push:
branches: [ master ]
jobs:
build:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Build with Mavens
run: mvn package