Table of Contents | ||
1 | Introduction | |
2 | Git installation | |
3 | Git configuration | |
4 | Git initialization | |
5 | Add and commit | |
6 | Git status | |
7 | Git branch | |
8 | Git merge | |
9 | Connect to github | |
10 | Push to github | |
11 | summary |
Introduction
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Installation
if you haven't install git on your system , click here and follow the path mentioned on the official website and download the appropriate version for your operating system. Follow the installation instructions provided on the website.
Git Configuration:
After installing Git, you'll need to configure it with your name and email address. Open a terminal or command prompt and run the following commands:
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
Initialize a Git Repository:
To initialize a git repo for your project , navigate to your project directory and run the below command:
git init
Add and Commit
To track changes of a file , you need to add them to the staging area and then commit them . use the below commands to add and commit the changes.
git add .
git commit -m "Initial commit"
Git status:
To check which files needed to commit and which files are untracked , run the below command:
git status
Git Branch:
If you are working on a group and you dont want to mess with the original files.you can create a copy of a file you would like to work on without messing up the original copy.You can either merge these changes to the original copy or just let the branch remain independent. To create a branch run below command
git branch branchName
you can shift from current branch to other branch using the below command:
git checkout branchName
Git merge:
If you want to merge your current branch to the main branch or some other. shift to the branch in which you want to merge .run the below command:
git merge branchName
Connect to Github:
If you haven't already, you'll need to create a github account at github.com and set-up a new repository. Once you have created a repository on GitHub, you can connect your local repository to the remote repository using the following command :
git remote add origin https://github.com/your-username/your-repository.git
Push Changes to GitHub:
To push your changes to remote repo on github you need to run following command;
git push -u origin master
This command will push your changes to the "master" branch of your remote repository. You may need to enter your GitHub username and password to authenticate.
Conclusion:
Git and GitHub are powerful tools for version control and collaboration in software development. By following this guide, you should have a basic understanding of how to use Git and GitHub to track changes to your code, collaborate with others, and manage your projects effectively.