Intro to Concepts of Git and GitLab

Git :-
It is and open source version control system used to track changes into our folders , known as repository in git language.
Git repository :- Folders/repo created by git to track changes of that particular folder.
git init :- It is the very first command we would discuss about. Using this will initialise a particular folder and would create a .git folder in it , that would keep track of all the changes being made in that folder.
git status :- It is used to check the status of all the updation being made till now. It tells about everything , about newly created files , updated files , deleted files etc.
Here we are currently on master branch which is the main branch on which you work on your projects. No commits yet tells that there are no changes made since creating the git repository.
git add :- Now suppose we create any file in this folder , .git folder would record that , but how do we come to know about these changes. It involves a series of step to be performed after making any changes.
STEP1 :- git add <file_name> :- It would add the particular file to a staging area. It’s an area where files are sent before committing them. In simple terms , you need to add first the newly created files before going to the next step i.e commit where you will keep a note for you and others , that what change is made at this period of time. Only staged files are commited at the same time.
git add . :- to stage all unstaged files and directories together.
STEP2 :- git commit -m “changes” :- It is a command to tell info about all the staged files and directories that changes has been made in these files and directories and what changes has been made.
After committing , when you will run git status it would show something like this :-
Here working tree clean simply means that everything is up to date in your repository i.e everything has been staged and commited.
Let’s now deep dive into more commands of git :-
git config —global user.name “username”
git config —global user.email “email id”
The above two commands are used to configure your git with a particular username and email oftenly asked to enter for the first time when you install and start using git.
git restore — staged file_name :- It is used to unstage the files.
git log :- It is used to view all the commits made till yet. It also contains unique hash id of each and every commit which can be used later to get back in time till that commit.
git reset <hash_id> :- It is used to get back in time till a particular commit whose hash - id you have mentioned.
git stash :- It is used to send all the staged files temporarily to a stash area from where they could be easily recovered using git stash pop command.
git stash clear :- It will remove everything permanently from stash area.
git diff :- It is used find difference of what is changed but not staged.
git diff —staged :- It is used find difference of what is staged but not committed.
git branch <branch_name> :- It is used to create a new branch.
git checkout <branch_name> :- It is used to change our branch.
git log branchB .. branchA :- Shows the commit on branch A , that are not on branch B.
git diff branchB … branchA :- Shows the difference of what is in branch A that is not in branch B.
git merge <branch_name> :- It would merge the mentioned branch into the main/master branch.
git rebase <branch_name> :- It is effective and efficient alternative of merging two branches , that excel in merging the branches more cleanly and linearly.
GITHUB :-
GitHub is a web-based platform that uses Git for version control and is primarily used for hosting and managing software development projects. It provides a collaborative environment where developers can work together on code, track changes, and manage different versions of their projects.
Every github project has it’s own URL (SSH/HTML) which could be used to link that github project with terminal of your machine.
git remote add origin URL :- Here origin is the alias or name given to the URL to use in future instead of the complete URL.
git remote -v :- It will tell about all the URLS attached to PWD.
git push origin master :- Here origin is the name of URL we had given in past and master is the branch we are sending to and from data.
git clone URL :- It is used to clone the entire project from github to our local machine.
FORK :-
It is a feature of github used to clone someone’s else project into our own github account so that we could edit particular projects.
PULL REQUEST :-
When you clone someone’s else project into your github account and then make some changes in it , when you need to reflect that changes into the owner’s github repo. you need to make a pull request which would be further agreed by the owner , whether to accept or not.
- git pull upstream main :- Basically this command is used to bring changes from github to your local machine. Here upstream is name of url of the github and main is the branch of local machine.
Merge Conflicts :-
A merge conflict in GitHub occurs when changes from different branches or commits conflict with each other and Git cannot automatically resolve them. This typically happens when two or more people have edited the same lines in a file or when a file has been deleted in one branch but modified in another.
To resolve a merge conflict, you need to:
Identify the Conflict: Git will mark the conflicting areas in the files with special markers. These markers will show the conflicting changes from each branch.
Manually Resolve the Conflict: Open the file in a text editor and decide which changes to keep. You can choose one side, combine changes, or make entirely new edits.
Remove Conflict Markers: After resolving the conflict, remove the conflict markers from the file.
Stage the Resolved File: Use
git add <file_name>
to stage the resolved file.Commit the Changes: Use
git commit
to commit the resolved changes. This will complete the merge process.Push the Changes: If you're working with a remote repository, push the changes to update the remote branch.
In conclusion, understanding the fundamental concepts and commands of Git and GitHub is essential for efficient version control and collaborative software development. By mastering these tools, developers can effectively manage code changes, collaborate with team members, and maintain a clean and organized project history. Whether you're working on a personal project or contributing to open-source software, Git and GitHub provide the necessary infrastructure to streamline your workflow and enhance productivity. As you continue to explore these platforms, you'll discover even more advanced features and techniques that can further optimize your development process.
Subscribe to my newsletter
Read articles from Aryav Luna directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
