Here comes part 4 for Git and GitHub for Beginners, in the previous three blog posts we had discussed git installation, how to create a repository, how the .git folder works, how to push files, and many more. If you haven’t read the basic theory part then I strongly recommended you to read the first three-part and then start practicing.
What is the need for branching in GIT?
As a developer, we work in a team, all the team members work on their individual task. Imagine that at the same time we upload our code in the main branch then it would be a mess. So, it is always good practice to create a separate branch parallel to the main branch and merge it when required.
Branches are part of everyday development work. It helps us to isolate our changes. We would like to keep the original as it is. We/Developer want to create, update and share the files with our team members in a completely isolated state and keep the original file safe.
Using branch what will happen others do not gets affected by your changes.
How do I create a Git repository branch?
git branch devHar0001
How do I know my head branch?
git log -2
How do I list only local branches?
How do I list all remote branches?
git branch -r
How do I switch to a different branch in git?
Git checkout is used for two main purposes.
1. Switch between branches.
2. To restore and made changes.
3. It can also be used to create and check out a branch.
git checkout -b devhar002_newformadd(Your_Branch_Name)
b: – stands for branch using the above command you can create and switch to new branch as well.
Checkout the parenthesis.
OR you can also use the command as I have specified down below.
For practice purpose create new file and write some code.
Git add . Git commit –m “your msg”
How do I switch from branch to master branch?
git log git checkout main
using git log checkout it may be main or master.
How do I switch to a specific commit in git?
git log git checkout 60f61 and hit enter
How do I push a branch to a remote branch?
git push origin -u devHar0001
How do I delete a local branch git?
Git branch –d yourBranchName
How do I remove branch from remote?
git push origin --delete devHar0001
How do I pull data from a Git repository?
Member 1 has uploaded all the data into the repository. If member 2 wants to download and interested to use it. He has to use the “git pull” command.
Git pull command consists of two steps internally, it runs “git fetch” and “git merge” sequentially.
Git Fetch: – Downloads files and changes from the remote repository but does not integrate them. In short, it download from remote and compare them to the local repository but didn’t bring the changes to local repository.
Git Merge: – Does integration data from the remote repository into the local repository.
git checkout devHar0001 git add . git commit -m "New Form" git log git push origin -u devHar0001
To create pull request we have two branch.
In our case we want to merge from “devHar0001” à “Main”.
Write pull request description.
Assignees: – Team leader of Head, who is in charge of marge call to the master branch.
Let’s do some changes to your remote text file and perform pull operation in our local system. (Imagine that the second team member has done some changes and I want to use it.)
Open git bash.
git pull git log -2
We synchronize the data from the remote repository and get the changes into our local repository. We are in an identical state with the remote repository.
How do I add someone to GitHub?
How do I give someone access to my git repository?
Click on send request.