What is a git?
Git is version control software, which is used to keep track changes on software files.
REPO➖
It store multiple software files in a single folder.
All used Commands
Basic Command
git version
→ used for check git version
git status
→ it shows which folders are tracked or untracked.
Project command
git init
→ used only for one time in a project.
git add
→ used for add file in current branch.
git commit -m "add your message"
→ It is worked like check points and used for comment in a pash.
git push origin main
→ it push git history on the git hun.
- git follow atomic commits. Means keep commit on an one feature or one component at a time.
- Commit must be order from. e.g.: Add navbar
- commit works:
- commit are depends on their parent commit.
- Each commits has their own hash code.
Git configure commands
git config --global [user.](http://user.name)email
→ this command configure your email address for globally. if you want to store your email for local project then use --local
instead of global.
git config --global user.username
→ it also did some thing.
git log --oneline
→ to see all commits in the current branch.
.gitignore
→ it is file. That is untracked by git. we can put file name which are private.
Git Branch and Conflict
- What is Branch ?
- Branch in git is known as a timeline. Different programmer can worked different timeline in same Repos. like some worked on hero section in a website and other one worked on Navbar. main is root branch.
git branch
→ it is used to create new branch.
git switch
→ it is used for switching different branches.
- we can replace switch with
checkout
. it did same work. - Head always point Main branch, where is current at.
If we not mange other branches, then one work in one branch is vanished from other branch. like Dr. strange
git branch
→ used to see all branch.
Green one is current branch where we staying.
Git Merge Different branch/timeline
- To merge different timeline with main. we must comes first on main branch. then type this command:
git merge <add_branchname_that_will_be_merge>
→ use to marge .
- ❗ sometimes conflicts happens when both programmer write code in same file.
- To mange conflicts we have three choice: 1. Accept both code. 2. Accept incoming code. 3. Accept main branch code.
- This process can be done by manually.
Git diff and stash
-
git diff
used for compare same file with current commit and previous commit. -
---
and+++
indicates changes in file, not deletion and insertion. -
git stash
is special command on git. for storing changes in temporary. don’t need add and commit before changing branches. - we can back our changes in any branches using this command.
-
git stash pop
→ used back stashed worked. -
git restore
→ it works same.
Rebase
Rebase is an alternative of merge and a cleaning tool. It is used for marge two different timeline into a single timeline.
❗ don’t run this command when you are on main branch. because it will change your commit history.
git rebase <branch_name>
GITHUB
Git is a version control and git-hub is a service to host git online.
- git work with SSH key, which is very sensitive. for more go git-hub doc.
Add Git into Github.
git remote add origin <url>
- connect git with git-hub repo.
git remote -v
→ check git-hub repo is configured or not.
git push -u origin main
→ used to send code base into the main branch in git-hub. -u
set upstream that allow us for future command git push
Disclaimer.
- when clone some repos, you just get main branch, rest of repos are not configured with main branch.
-
Top comments (0)