Git Basics:
Configuring Git:
After installation, open a terminal or command prompt and set your name and email address:
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Creating a New Repository:
To start using Git, you'll need to initialize a repository. Navigate to the directory where you want to
create your project and run:
git init
Adding Files:
Use git add to stage files for the next commit. For example:
git add file.txt
Committing Changes:
Once you've staged the changes, you can commit them:
git commit -m "Your commit message"
Checking Status:
To see the status of your repository, use:
git status
Viewing Commit History:
You can view the commit history with:
git log
GitHub Basics:
Creating a New Repository on GitHub:
Click on the '+' sign in the top right corner and select "New repository". Follow the instructions to
create a new repository.
Pushing to GitHub:
To push your local repository to GitHub, you'll need to add a remote. Replace username and
reponame with your GitHub username and repository name:
git remote add origin https://github.com/username/reponame.git
Then, push your code to GitHub:
git push -u origin master
Cloning a Repository:
To work on an existing repository from GitHub, you'll need to clone it:
git clone https://github.com/username/reponame.git
Pulling Changes:
To get the latest changes from the remote repository, use:
git pull origin master
Branching:
Create a new branch for development using:
git branch new-branch
Switch to the new branch:
git checkout new-branch
Merging Branches:
After making changes in a branch, you can merge it back into the main branch (usually master):
git checkout master
git merge new-branch
Pull Requests:
When working with others, it's common to make changes on a separate branch and then create a
pull request on GitHub. This allows others to review your changes before merging them into the
main branch.