What is Git?
Git is software that runs on your computer and manages your files. Free and open-source version control system. It lets you track changes you make to your files over time.
What is GitHub?
GitHub is an online hosting service for Git repositories. Allows collaboration.
Repository- project/folder. The folder where your project is.
Install Git & Create a GitHub account.
Git Architecture
What is a branch in git?
The branch is used to keep your changes until they are ready.
You can do your work on a branch while the main branch(master) remains stable. After you are done with your work, you can merge it into the main branch.
Commands in Git
Demo on Git
Let us implement some git commands on git using git bash.
- Check the version of git
git -- version
Configuring Git.
Replace USERNAME with the username that you created on GitHub
Replace EMAIL with your email address
git config --global user.name "USERNAME"
git config --global user.email "EMAIL"
- check if configured
git config --list
- Create a directory "gitdemo" in your local machine
mkdir gitdemo
- Move to the "gitdemo" repository
cd gitdemo
- Initialize your git repository
We need to tell git this is a git repository.
git init
- Create a file called test.txt in the folder gitdemo, write something and save it.
- Check the status of your repository.
git status
-to find out what is happening.
- Add the "test.txt" file created to make a commit.
git add test.txt
git add .
Check the status again.
- Commit the changes with a short message.
git commit -m " YOUR MESSAGE HERE"
Make changes to the file and save it again.
- View the changes
git diff
- Create a remote repository.
- Copy the link
- Connect your local repository to the remote repository.
git remote add origin ...
- Push the file to the remote repository.
git push origin master
reload GitHub
Branching and Merging
Create a new branch
git checkout -b tbranch
check the branch you're currently using
git branch
make changes to test.txt file
check the status again
git status
Commit the changes and push
Check the differences between the branches
git diff master
Go back to the master branch
git checkout master
Merge the branches then push.
git merge tbranch
git push -u origin master
Cloning.
A clone
is a full copy of a repository, including all logging and versions of files.
If you want to get a copy of an existing Git repository — for example, a project you’d like to contribute to — the command you need is git clone
.
git clone <link here>
GREAT LEARNING!!