Brief guide to mess around with Git and Git-hub

ยท

6 min read

What is git hub then?

GitHub is like a big library where people can share and work on computer programs together. Think of it like a place where you can find lots of books, and also write and share your own stories with other people.

Need a bit more explanation?

GitHub is a website and service that allows people to store and share their computer code with others. It's a platform for developers to collaborate on software projects, track changes to their code, and share their work with the public. It also provides tools for project management, code review, and documentation.

Git is a version control system that allows multiple people to work on the same codebase without causing conflicts. Each person can make changes to the code, and then "commit" those changes to a central repository on GitHub. The repository keeps track of all the changes that have been made, so if someone makes a mistake or wants to go back to an earlier version of the code, they can easily do so.

Many open-source software projects, as well as many private projects, use GitHub as a central location to store and share code. It also has a large community where developers can ask questions, share their work and get feedback, and find libraries, frameworks, and other tools to help them with their development.

TLDR: git allows you to know which person made which changes in the project, which is helpful in large projects.

So do we get started with it?

Installation on Ubuntu

To install Git on Ubuntu, open a terminal and enter the following command:

sudo apt-get install git

This will install the latest version of Git on your system. Once the installation is complete, you can verify that Git is installed by running the following command:

git --version

This will display the version of Git that is currently installed on your system.

git version 2.34.1

once you have installed the git on the system, you are good to learn the basics.

let us make a local repository aka folder aka directory on the desktop name as gitblog

mkdir gitblog
#change the pwd (present working directory) to gitblog using cd command
cd mkdir

mkdir command creates a new folder and cd is used to change the directory on the linux terminal

to initiate the git in present working enter the following command:

git init

#output
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint:     git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint:     git branch -m <name>
Initialized empty Git repository in /home/sourabh/Desktop/gitblog/.git/

you have initiated the git present working directory to check it please enter the command :

ls -la
#output
total 12
drwxrwxr-x 3 sourabh sourabh 4096 Jan 25 00:54 .
drwxr-xr-x 8 sourabh sourabh 4096 Jan 25 00:54 ..
drwxrwxr-x 7 sourabh sourabh 4096 Jan 25 00:54 .git

ls command is for listing objects/files present in the directory and ls-la shows hidden files also

to check the status of Git in your directory enter the following command:

git status
#output
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

now you have installed git on your system and initiated the git in PWD.

now let us add a new file to the current directory using vim:

vim hashnodeblog.py

to write something in the vim prompt in the terminal you need to enter the insert mode by pressing i

once you are in insert mode, enter the text or code you want to add to the file



print("Hello friend")

to exit vim enter the following command in vim:
Esc (to exit from the insert mode)

:wq

w stands for write and q for quit

once you have exited vim enter the command:

git status

the status command shows us the current state of the working directory

The three stages

  • Modified

  • Staged

  • Committed

"Modified" refers to changes made to a file that has not yet been saved to the version control repository. "Staged" indicates that those changes have been marked for inclusion in the next commit, but have not yet been saved. "Committed" means that the changes have been saved and are now a part of the project's history in the local repository.

so currently our file is in an untracked area.

So what are untracked files then? you may ask.

Untracked files are files in a Git repository that have not yet been added to the repository's version control. These files are not being tracked by Git, and changes made to them will not be included in commits until they are explicitly added to the repository. To add untracked files to the repository, they must be explicitly added to the staging area using the "git add" command, after which they will become "staged" files and will be included in the next commit.

So what's the difference between untracked and modified?

The main difference between untracked files and modified files is that untracked files have not yet been added to the version control system while modified files have been added and are being tracked by the version control system but their changes haven't been committed yet.

An untracked file is a file that is not being monitored by the version control system and is not part of the repository. Any changes made to an untracked file will not be reflected in commits or shared with other collaborators until the file is explicitly added to the repository using the "git add" command.

On the other hand, a modified file is a file that is being monitored by the version control system and is part of the repository, but its changes haven't been committed yet. Any changes made to a modified file will be reflected in commits and shared with other collaborators once the file is committed using the "git commit" command.

so lets add the files in our version control system

once we have added to the file we commit. to commit you to have to enter the following command:

git commit -m "first commit or your choice of words"

the output for that be like

as we can see that 2 files changed which are hashnodeblog.py and hashnodeblog.txt

now if we see the the status of a directory using the command git status

we will se3 an output something like the following output:

now let us change the file hashnodeblog.py once again by changing the following lines.

to see the status enter the command git status

previously we added all file using the command git add . but if we want to add a single file we can use git add (filename ) .

ok wait previously it was red now its green what does that mean

A green file in a git repository indicates that it has been committed with the latest changes. A red file, on the other hand, indicates that it is in the repository but the latest changes have not been committed. If you use the "git commit" command, only the red-marked files will be selected for committing.

This blog is currently incomplete I'm thinking to add a complete method pushing code and making pull requests, getting ssh configured.

And for the sake of fun

ย