Version control systems (VCS) are essential tools for tracking changes in software projects, allowing you to maintain a complete history of modifications made to your codebase. This enables developers to easily collaborate, track progress, and revert changes if needed.
Git is a popular distributed version control system designed for handling projects of all sizes with speed and efficiency. It is widely used by developers around the world and has become the de facto standard for version control.
To install Git on a Linux system, follow these steps:
- Open a terminal.
- Update the package list by running:
sudo apt update
- Install Git with the following command:
sudo apt install git
- Verify the installation by checking the Git version:
git --version
- Configure your Git username and email:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
You have now successfully installed Git on your Linux system.
GitHub is a web-based platform for version control and collaboration using Git. It provides a simple and user-friendly interface for managing and collaborating on software projects.
- Sign up for a GitHub account or sign in to your existing account.
- Click on the "+" icon in the upper-right corner, and select "New repository."
- Enter a repository name, add an optional description, choose visibility (public or private), and click "Create repository."
- Copy the repository URL from the "Quick setup" section.
- On your local machine, open a terminal and navigate to the directory where you want to clone the repository.
- Run the following command to clone the repository:
git clone [repository URL]
You have now created a GitHub repository and cloned it to your local machine.
-
Fork a repository on GitHub by clicking the "Fork" button at the top right corner of the repository page.
-
Clone the forked repository to your local machine:
git clone [forked repository URL]
- Create a new branch for your changes:
git checkout -b [new branch name]
- Make changes to the files and commit them:
git add .
git commit -m "Your commit message"
- Push your changes to your forked repository:
git push origin [new branch name]
-
Go to the original repository on GitHub, and click on the "Pull Requests" tab.
-
Click on the "New Pull Request" button, and choose the branch you just pushed from your forked repository.
-
Review your changes and click "Create Pull Request."
You have now created a pull request in Git.
- Navigate to your local repository in the terminal.
- Create or modify a file in the repository.
- Stage the changes using:
git add [file name]
To stage all changes in the repository, use:
git add .
- Commit the changes with a meaningful commit message:
git commit -m "Your commit message"
- Push the changes to the remote repository on GitHub:
git push origin [branch name]
Your changes are now pushed to the GitHub repository.
Branching allows you to create a separate line of development within a repository, enabling you to work on features or fixes independently from the main branch. This makes it easier to manage and maintain code, especially in large projects with multiple contributors.
- Navigate to your local repository in the terminal.
- Create a new branch with a descriptive name:
git checkout -b [new branch name]
- Verify that you have switched to the new branch:
git branch
You have now created a new branch in Git.
Switching branches allows you to move between different lines of development in your repository.
- List all branches in your local repository:
git branch
- Switch to an existing branch:
git checkout [existing branch name]
- Verify that you have switched to the desired branch:
git branch
You have now successfully switched branches in Git.
Merging branches in Git is the process of combining changes from one branch into another. This is commonly done when a feature or fix is completed and ready to be integrated into the main branch.
- Ensure that you have committed all changes in the branch you want to merge.
- Switch to the target branch:
git checkout [target branch name]
- Merge the changes from the source branch into the target branch:
git merge [source branch name]
- Resolve any merge conflicts if they occur, and commit the changes.
- Push the updated target branch to the remote repository:
git push origin [target branch name]
You have now successfully merged branches in Git.
This completes the content for your README.md file on version control systems, Git, and GitHub.
The "git switch" command is an alternative way to switch branches in Git, introduced in Git version 2.23.0. It provides a more straightforward and user-friendly method for switching branches compared to the "git checkout" command.
- List all branches in your local repository:
git branch
- Switch to an existing branch using the "git switch" command:
git switch [existing branch name]
- Verify that you have switched to the desired branch:
git branch
You have now successfully switched branches using the "git switch" command.
You can also create a new branch and switch to it using the "git switch" command in a single step:
git switch -c [new branch name]
This command will create a new branch with the specified name and switch
- Step 1 - Loging to github
- Step 2: Create a Repo
- Step 3 : Click on your user profile and clicl on stetting
- step 4: Click on ssh key
- step 4.: Copy and paste your pub key
- Step 6: Click OK
- Step 7: Clone your repo
- Step 1: Login to lab VM and open terminal
- Step 2: runthe following command
ssh-keygen
Enter three time to create the public & private key
- Step 3 : copy the content of you
id_rsa.pubkey
cat ~/.ssh/id_rsa.pub
- Step 4 : Paste the content in privious step 6