DEV Community

Joyce chepleting
Joyce chepleting

Posted on

A beginners guide to Git and Github

Definition of Git and Github

This two may seem familiar to someone new but they are not.
Git is a free, open source software usedfor tracking changes in file and managing version history locally.
Github on the other hand is web-based platform that provide hosting repositories, team collaboration and project management.
In conclusion, you do not need Github to use Git but you need Git to use Github.

Connecting Git to Github account

Step 1Install Git : you can downloadit from the official Git website
Step 2 :Create a Github account if you don't have one already.
Step 3Configure Git with your credentials : open your terminal or command prompt and set your username and email address, which will be associated with your commits:

Step 4Create a repository on github: Login to GitHub.com , click the + sign at the top right corner and select New repository.
Step 5 : Name your repository and click create repository.
Step 6: Authenthication. When you connect to a GitHub repository from Git, you need to authenticate with GitHub using either HTTPS or SSH.
-Connecting using HTTPS,which is normally recommended means you can cache your GitHub credentials in Git using a credential helper.
-Connecting over SSH means you must generate SSH keys on each computer you use to push or pull from GitHub.

You now have Git and Github.This means you can now create a repository where you can store your project as a form of backup and you can share your work globally.

What is Git and why is version control important

Git is a free open source device version control.
Version control systemtracks and records changes to any file (or a group of files) allowing you to recall specific iterations later on or as needed.This system allows people in different locations to work collaboratively on a project.
This is what Git allows users to do. Individuals can work on a project locally (on their own computers), save any changes that work, then synchronize those changes to a Git repository so others can see their newer version.

Importance of version contol

  1. Reversion.The in depth tracking helps make it easier to return to earlier version if needed.

2.Attribution. Every change made can be made to a team member.

3.Team can separate form branches and work on different projects then merge.

4.Concurrency.Git enables these developers to work concurrently while helping to prevent any conflict between each developer’s changes.

5.Helps in better organization and communication.This happens when members commit messages(they explain where changes were made and why by writing a message).

Git PUSH

The git push command is used to transfer or push the commit, which is made on a local branch in your computer to a remote repository like GitHub. The command used for pushing to GitHub is given below.

git push 'remote_name' 'branch_name'

  1. create a new repository You need to create a new repository and click on the plus sign.

Fill up all the required details, i.e., repository name, description and also make the repository public this time as it is free.

2.Open your Git Bash
3.Create your local project in your desktop directed towards a current working directory
pwd stands for 'print working directory', which is used to print the current directory.
Move to the specific path in your local computer by cd 'path_name'. The cd commands stand for 'change directory' and it is used to change to the working directory in your operating system, and to locate your file, 'path_name', i.e., C:/Users/Dell/Downloads/FaceDetect-main needs to be given. This command can identify the required file that you are looking to work with.
4.Initialize the git repository
Use git init to initialize the repository.

  1. Add the file to the new local repository Use git add . in your bash to add all the files to the given folder. Use git status in your bash to view all the files that are going to be staged to the first commit. 6.Commit the files staged in your local repository by writing a commit message You can create a commit message by git commit -m 'your message', which adds the change to the local repository. git commit uses -m as a flag for a message to set the commits with the content where the full description is included, and a message is written in an imperative sentence up to 50 characters long and defining "what was changed", and "why was the change made".


7.Copy your remote repository's URL from GitHub
The HTTPS or URL is copied from the given GitHub account, which is the place of the remote repository.
8.Add the URL copied, which is your remote repository, to where your local content from your repository is pushed.

  1. Push the code in your local repository to GitHub git push -u origin main is used for pushing local content to GitHub.

In the code, origin is your default remote repository name and -u flag is upstream, which is equivalent to -set-upstream. main is the branch. name.upstream is the repository from which we have cloned the project.

Fill in your GitHub username and password.

How to pull code from Github

-GitHub Desktop provides a graphical interface for these operations.
-Open GitHub Desktop.
-Click the File menu and select Clone repository... (for the first time) or select your existing repository from the list (to get updates).
-If cloning, select the repository from your GitHub account or paste the URL, choose a local path, and click Clone.
-If updating an existing repo, simply click the Fetch origin or Pull origin button in the top bar to sync your local branch with the remote.

Tracking File Changes Using Git

Tracking file changes using Git enables effective version control by recording updates and maintaining a clear history of file modifications.Keeps a complete version history of files.
Helps review and manage changes over time.
Viewing Commit History of a File in Git
It helps identify when and how a file was modified across different commits.

Step 1: Check the Current Status of Repository
It's a good practice to check the current status of the Git repository before starting to view the change history of a filE
This will display the current state of the repository, including any untracked, modified, or staged files.

Step 2: View the Change History of a File
To view the change history of a particular file, use the git log command.

Step 3: View the Changes Made in a Commit
To view the changes that were made in a particular commit, we can use the git show command.

git show commit-hash

Top comments (0)