0% found this document useful (0 votes)
48 views18 pages

Git & GitHub Documentation by Krishna

Uploaded by

Krishna Vardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views18 pages

Git & GitHub Documentation by Krishna

Uploaded by

Krishna Vardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Git & Git Hub Tutorials by Krishna Vardhan

Saturday, 13 April 2019 19:31

Here is the Git& Git Hub tutorials Documentation which will guide you through out the process. This document would be helpful for students, developers, and also
team leads/managers or project creators as well since it guides you to the process of merge request as well.

I have used Windows OS but the process is similar or same for MacOS and Linux users as well.

Prerequisites:

• Download & Install the Git Application.


https://git-scm.com/downloads
• Create you GitHub account.
https://github.com/
Firstly, remove the assumption that both git an GitHub are same. No they are not.
The difference between Git and GitHub are:

Git:
1. Git is a system for tracking changes in computer files and coordinating work on those files among multiple people.
2. It is a command-line tool that operates on your local computer.
3. Git is a version control system that enables you to manage and track changes in your codebase.

GitHub:
1. GitHub is a web-based platform that provides hosting services for Git repositories.
2. It's a platform for sharing and collaborating on Git repositories.
3. GitHub offers a web-based interface with additional features like issue tracking, pull requests, and project management tools.
4. It allows multiple people to work on the same project remotely and collaborate more easily.

Simply, Git is the tool you use on your computer to manage code changes, while GitHub is a website that hosts Git repositories and offers a user-friendly interface
to collaborate and manage projects using Git.

After installing the Git Application, open the command prompt on windows OS or Terminal on MacOS or Linux, and follow these commands:
"git config user.email "your@email.com""
"git config user.name "your name""

This is a one-time setup process, and you won't have to do it again. You can provide your information voluntarily before it's asked, or you can do it later
when a pop-up appears, like the one shown in the image below (which comes up after you've initialized the Git application in your cmd/terminal). Don't
worry, this document also explains how to "git init" as well. Please don't think that "git init" is a requirement for this. Hahaha!

Part 1 - For Developer or Students


Here we go,

There are 4 stage when working with the Git. They are as follows:
1. Remote Repository
2. Local Repository
3. Staging Area
4. Working Directory
Let us 1st understand the 4th one i.e. working directory.
Once the git is installed, go to a the specific folder where you want to keep it in server.
After opening it, in the directory path in the above navigation bar, click on it and write CMD and click enter as command prompt get opened in the directory area as shown in below
example pictures:
Let us now understand the 3rd one, i.e. Staging Area. The staging area is where the files are yet to be committed to local repository. The staging area is the location where single files
can be added specifically by the user. Remember that, in the local repository, we cannot add the single files but only batch files can be added. This is the reason we are adding files
specifically to the Staging area. [Staging Area -> Single Files ; Local or Remote Repository -> Batch Files]
To do so, use this command: "git add [file or folder name]".

Note: In case if I want to add any non-existing file or folder, it shows and error:

Now the files are added and are in the Staging Area that are yet to be committed. Hence staging area is completed.
Let us now understand the 2nd one, i.e. Local Repository. This is the area to commit the changes or files, firstly, check the status if the files are yet to be committed or not by using "git
status" command in your directory. You shall see the files that are to be committed as shown in below image.
Here, I have added Documentation as well, so committing that also.

Secondly, we have to commit to local repository. To do so, use the command, "git commit". However, you can add a message which is optional to user, and to do so, use this command,
"git commit -m "your message""

Now all the files are committed which means the local repository is also completed. Moving on to 1st one, Remote Repository, this is where the files are stored in a remote server. You
can use any remote repository hosting services like GitHub, Bitbucket, GitLab, Perforce, SourceForge, AWS: Code commit, Microsoft Azure DevOps, and others.
But we will use GitHub as our host repository as it is free to use and open source. Host means nothing but the one who holds or stores our code in our server that can be accessed
remotely.
Create a GitHub account.
After creating, click on "New" to create a new repository.

or

Follow these steps:

Fill in the details, and click on Create repository. You can add Readme description later.
Fill in the details, and click on Create repository. You can add Readme description later.

As shown in the below images, you can either choose HTTPS(Hyper Text Transfer Protocol Secure) or SSH(Secure Shell) directory based on your choice, and the operation would
be the same however.

Image A- SSH:

Image B - HTTPS

I have chosen HTTPS and please follow the instructions in your command prompt:
1. To add the URL to your git so that all that changes are committed in this repo, use this command:
"git remote add origin [link or SSH key]". Refer below image for clear understanding:
2. Let us understand about the branches later, but for now we are updating our files or folders into main/master branch. For now assume like it is the main folder. Write this command:
"git branch", and you get the master as your branch.

3. Push command - This is the main command where our files are uploaded to the remote finally.
Use this command: "git push -u origin master"
You might be asked to connect to GitHub by browser for Authorization access. Just allow it.

This process might take for few seconds, and after successful execution, open your GitHub master repo and check if all the files or folders are added into master repo or not.
With these, the codes are uploaded into our repo. We haven't completed yet. We need to understand about branches, merge, pull request as well.
People who work on community or open source projects like Arogya Sethu, where any developer can try making changes and updates in GitHub or want to contribute work in the codes
or works, should be aware of these branches. To contribute work in the codes or works, you must be associated with a branch. Only then pull request or merge can be accessed and
understood. These are particularly used in companies where numerous developers are working on a single project.
The above procedure might sound little complex. Yes, it is a little complex but with most practice and easy understanding, we can achieve.
Let me take care of easy understanding for you.
ABC Developers, a company that creates embedded processors, manages their code in a simple and easy-to-understand way:
ABC Developers has a team of 10 developers, and they all work on different features to make the code work efficiently. However, they can't all work directly on the main code, which is
called the "master." Instead, they use something called a "branch."
Think of a branch as a separate copy of the code. Each developer creates their own branch to work on their changes. So, when they make improvements or add new features, they do it
in their own branch, not in the main/master branch.
Once they've made their changes in their own branch, they can upload or "commit" those changes just like above procedure. But when they do this, they don't write the command with
branch name as master instead they use their own branch's name.
Now, here's where the "pull request" comes in. A pull request is like asking the boss, who is probably the team lead or manager, to consider their changes and possibly add them to the
main code (the master branch).
But there's a catch. The boss will only add the changes if there are no "merge conflicts." A merge conflict is like when two people try to change the same thing in the code, and the
computer doesn't know which change to keep. So, to avoid this, the developer can make sure their changes don't clash with what's already in the main code.
This way, each developer can make as many improvements as they want in their own branch without messing up the main code. It's a useful method that many companies use to keep
everything organized and working smoothly.
I hope you got an idea, now let us understand this step by step.
How do we create a branch?
Simply go to the command prompt, and use this command:
"git checkout -b "your branch name""
In case if there are already branches created and you want to jump from one branch to another, then use this command:
"git checkout"

You can check the same by running "git status" command if your files or folders are moved to Dev1 branch or not.

Or, you can use :git branch" command to see where you are currently located. The green writing is the present branch location that you are working on.
Adding Files and Folders into new branch - Now, we shall add our Presentations folder into Dev1.

Push to Remote Repository - i.e. To our GitHub branch.


Use this command to push the code in your branch:
"git push --set-upstream origin [branch-name]"

Check in GitHub - Open the GitHub website, or refresh to see the your branch and its associated folders that are uploaded in Dev1.

Pull Request - In the same page of your website, you can see a click option as "Compare and Pull Request". So what it actually does is, it will send a pull request to the host
manager[could be your team lead/manager] to merge the changes that you have made into the master.
After clicking on it, you will be redirected to "Open a Pull request page", and you are supposed to write down your comments and request to merge to your host manager[team
lead/manager] by clicking on "Create a Pull request".

After doing so, you might be getting the same page as below, which says "Merge Pull Request"
In our case, we are the team lead or manager and also we are only the developers. So the complete privilege is given to us to merge the pull request. In case if you are working for a
public project or a company, then you might not see this. In that scenario, only the manager would be seeing it.
Now I shall make the merge pull request after reviewing the same, and it asks for confirmation as well. In case if you don't want to merge, you can "Close the pull request" otherwise
you can click on "Confirm merge"
I have chosen to confirm merge, and the files are now merged into the mater as shown

You can see the same in your repo, and the comments are also visible clearly like "Committing Presentations folder to Dev1"
Up to this point, we've covered the essential steps in the process: creating a branch, adding files to it, pushing changes to the branch's origin, creating a pull request, and merging the
pull request. These are the key steps that any developer should be familiar with.
However, there's more to the process, which typically is applicable to team leads or project creators. This additional part of the process is often relevant when the code or project is
open source, meaning it's accessible to the public, and anyone can contribute by making changes. In such cases, it's the responsibility of the team leads or project creators to manage
and review these external contributions.

Part 2 - For Team Leads/Managers or Project Host Managers


This section teaches us about "conflict merge," a technique employed by host managers in both companies and open-source projects. Let's clarify by using any open-source project from
GitHub.
Also for students and developers, You will discover how to clone a remote repository into your local repository in this section.

Let us dive in.

Let us take a repo and work on it. In this scenario, I shall take a repo called lowlevelprogramming-university. Please remember that our host manager is "gurgio"
In this repo, you are not allowed to create a branch since it is not our space. But we can create a copy of it in our own GitHub space.
To create a copy other repo, click on "Fork" option which is visible on the top of that repo.
You can edit your Repository name and click on "Create Fork".
Now that you have created a copy inside your work space, you will have the permissions to do what so ever such as creating branch, making changes or others.

Next, In your repo, click on the "<>Code" option, select HTTPS or SSH(either of your choice), and copy the link or key as shown.

Further, go to your local desktop or the folder directory where you usually keep your projects, and create a new folder with the project name.
Open the CMD in the directory.

Here, we need not initialize the git because, the project is already in remote and we want to copy it to our local repository.
To do so, follow this command:
"git clone [paste the project link or SSH key here]". The cloning process will begin.

Once after the cloning is done, you can check the same in your project folder as well.
After making your contributions, you can upload the code into your branch in the GitHub by usual procedure.[Follow initial procedure to how to upload your files or folders into
GitHub].

Once you are done with it, you can give a pull request which will directly ask the host manager of this project that is "gurgio" , and he/she shall look into the changes and merge the pull
request if they are satisfied.
In case he/she finds any "merge conflicts", he will review it as shown in below images:

Image a: Here, the host got an conflict message and he is asked to resolve it.

Image b: Conflicts are shown like this:

This means that, the host is saying that "check your code again and make sure there are no conflicts. Take the master files in which changes are made and update again to accept the
pull request"
So the user[you], have to go back to make changes and resolve conflicts.
Now go to cmd and follow the same commands as shown in Image c: Commands to merge
1. "git checkout master" - This command will move the changed files to your master
2. "git pull" - This command will bring all the changes that were made to make the changes.
3. "git checkout [your-branch-name] - This command will move to your branch
4. "git merge origin/master" - This command will merge the changes automatically if there are no conflicts raised.
But you will get an error here as there are conflicts.
Now that all the changes are merged, so the code is also merged right? So open your code editor (example VS code or Vim Editor), and you will automatically see the merged code
there. Now you can choose any action such as:
1. Editing the code without any duplicates, or
2. Allow the duplicate lines.
In VS code, you will direct have the option to choose and you can choose one.[As shown in below image]

You can choose one and save it.

Now the user that is you can upload the code to remote again and ask for raise the pull request, and hence the host manager shall approve the merge pull request to his [main project
code] master.
This is the complete procedure to handle the conflict merge.

Theory: What is merge conflict?

Let's use our ABC Developers example to illustrate what a merge conflict is:

Consider Harsha and Vamsi, two developers, each working on a separate branch of the code. Both of them want to alter the same line of code, say one that calculates a certain value.

Now, the computer becomes perplexed when they attempt to integrate their changes back into the primary code (the "master" branch). Due to the fact that Vamsi and Harsha both
made separate edits to the same line, it is unsure of whose change to keep. We refer to this uncertainty—the computer's inability to select which update to accept—as a "merge
conflict."
A merge conflict, to put it simply, occurs when two people attempt to change the same part of the code, and the computer is unsure which change to accept. The computer is
essentially saying, "Hey, I'm not sure which of these changes is right; you need to help me decide!" The decision to keep certain changes must then be made by the developers, who
must manually resolve the conflict.

This is the end of the documentation. Hope you loved it!

Regards,
Krishna Vardhan
Firmware Developer

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy