Git:-
Git is a version control system that allows you to track changes to files and coordinate work on those files among multiple people. It is commonly used for software development, but it can be used to track changes to any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
GitHub:-
It is a platform and cloud-based service for software development and version control using Git, allowing developers to store and manage their code. GitHub is a very popular platform for developers to share and collaborate on projects, and it is also used for hosting open-source projects. The interface also offers developers access control, collaboration features, and various task-management tools.
Version Control & their types:-
It is the practice of managing changes to source code. A system that tracks the changes done to a file/ files over time so that we can recall specific versions when needed.
There are two main types of version control systems:
Centralized version control systems(CVCS):-
It uses a central server to store all the versions of a project’s files. Developers “check out” files from the central server, make changes, and then “check-in” the updated files. Examples of CVCS include Subversion and Perforce
Distributed version control systems(DVCS):-
It allows developers to "clone" an entire repository, including the entire version history of the project. This means that they have a complete local copy of the repository, including all branches and past versions. Developers can work independently and then later merge their changes back into the main repository. Examples of DVCS include Git, Mercurial, and Darcs.
some commands
Here, we have done our lab in the AWS account
ec2-user:- login to our ec2
sudo su:- given root permit
yum update -y:- update our instance
adduser (given username)
su - sami:- login as sami
yum install git -y:- install git
which git:- checking whether git is install or not
git--version :- check version of the git
git config —global user.name “thesamiksha”
git config —global user.email “sami.spkt0@gmail.com”
git config —list:- used to see if our name and email are saved or not
mkdir demo-git :- making directory with name demo-git
cd demo-git:- Now, we are inside the directory demo-git
git init:- initialized empty git repository
cat >demo-file:- Create a file and paste our code
git status:- check the status of git
git add. :- adding our demo-file to the git
git commit -m “my first commit”:- Now, we are at our main branch
git status
git log:- This is used to see the running records of commit
Go to GitHub and create a new remote repository for your project.
Copy the URL of the remote repository to your clipboard.
In your local repository, run the following command to add the remote repository:
git remote add origin <remote repository URL>
To push your local repository to the remote repository, run the following command:
git push origin master
This command pushes the “master” branch of your local repository to the “origin” remote repository.
Create a repository named “Devops” on GitHub.
Connect your local repository to the repository on GitHub.
Cloned the repo first
Push your local commits to the repository on Gitub
Git Branching:-
Git branching is a feature in the Git version control system that allows developers to create multiple independent branches of their codebase, enabling them to work on different features or fixes simultaneously without affecting the main codebase.
git branch branch1:- To create new branch
git branch:- To check whether branch is created or not
git checkout branch1:- To switch between branches (In our case, we have branch named “branch1” so,)
Git Merge:-
Git merge is a command that allows you to combine the changes from two or more branches into a single branch. When you run git merge
, Git will automatically try to merge the changes made in the source branch into the target branch.
Merging is a common way to integrate changes from other branches into your working branch. It creates a new commit that represents the combination of changes.
- git merge <branch_name> :- To merge code from another branch, we use
GIT Stash:-
This is useful when you need to switch to a different branch to work on something else, but you don’t want to commit the changes you’ve made in your current branch yet.
git stash
git stash list:- to see all the stash file
git stash apply stash@{0} —— now again code can be restore and we can add and commit file
git stash clear ————-stash file remains in the stashing stage until we delete it so we use this command