Basic to Advance Git & GitHub

Basic to Advance Git & GitHub

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:

  1. 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

  2. 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

  1. ec2-user:- login to our ec2

  2. sudo su:- given root permit

  3. yum update -y:- update our instance

  4. adduser (given username)

  5. su - sami:- login as sami

  6. yum install git -y:- install git

  7. which git:- checking whether git is install or not

  8. git--version :- check version of the git

  9. git config —global user.name “thesamiksha”

  10. git config —global user.emailsami.spkt0@gmail.com

  11. git config —list:- used to see if our name and email are saved or not

  12. mkdir demo-git :- making directory with name demo-git

  13. cd demo-git:- Now, we are inside the directory demo-git

  14. git init:- initialized empty git repository

  15. cat >demo-file:- Create a file and paste our code

  16. git status:- check the status of git

  17. git add. :- adding our demo-file to the git

  18. git commit -m “my first commit”:- Now, we are at our main branch

  19. git status

  20. git log:- This is used to see the running records of commit

  21. Go to GitHub and create a new remote repository for your project.

  22. Copy the URL of the remote repository to your clipboard.

  23. In your local repository, run the following command to add the remote repository:

    git remote add origin <remote repository URL>
    
  24. 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.

  1. git branch branch1:- To create new branch

  2. git branch:- To check whether branch is created or not

  3. 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.

  1. 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.

  1. git stash

  2. git stash list:- to see all the stash file

  3. git stash apply stash@{0} —— now again code can be restore and we can add and commit file

  4. git stash clear ————-stash file remains in the stashing stage until we delete it so we use this command