GitHub
Introduction
What is GitHub and Why Do We Use It??!
GitHub is a code hosting platform for version control that provides a web-based interface for version control. it allows developers around the world to work together collaborate and track changes to manage the project. GitHub is built on top of Git, which is a distributed version control system that allows developers to manage changes to their codebase over time, and to roll back to the previous version of code if necessary.
Getting started:
To get started working on git hub, First, we need to go to github.com and create an account on GitHub, create a Repository, and then start working.
💡 Repository
The repository is a set of files that makes up a project and contains all the developer's code, documentation, and the assets of the project.
There are a few essential terms you need to know while using GitHub. Here are some of the most important ones that you can do manually and also by using Terminal:
-
Branch: A branch is a copy of a repository that is used to track changes to the code. Branches are often used to work on new features or bug fixes without affecting the main branch of the code.
# for creating a new branch git branch <branch_name, branch_name2> # for switching between branches git checkout <branch_name> -
Commit: A commit is a snapshot of the code in a repository at a particular point in time. Commits are used to track changes to the code and to revert to previous versions of the code if necessary.
git commit -m "write your commit" # If you have lots of changed files in your work, and want all of them included in the next committ git commit -a -m "Change titles and styling on homepage" Push command is used to transfer or push the commit, which is made on a local branch in your computer to a remote repository in GitHub. The command used for pushing to GitHub is given below.
git push 'remote_name' 'branch_name'
git push -u origin master
💡 In the code, the origin is your default remote repository name, and the '-u' flag is upstream, which is equivalent to '-set-upstream.' and the master is the branch, name. upstream is the repository that we have cloned the project.
- A Remote command in Git is a common repository that all team members use to exchange their changes.
git remote
RemoteNAME
git remote -v
origin https://test@github.com/test/example.git (fetch)
origin https://test@github.com/test/example.git (push)
💡 Using {git remote -v } it will show you the name of the Remote Repository and the URL behind the Repository We can see have this fetches and pushes commands correctly.
- {git branch -r} simply means that we have a connection between our local master branch and the master branch in our remote repository.
git branch -r
Origen/master
what we can see right here we basically have our remote repository which we point you to with name origin inside this repository we have the master branch and that’s exactly how the connection is established between our local repository and remote repository, and this remote branch is automatically created whenever we type certain git commands, for example, git pull or git push
- Clone: is a Git command line utility used to target an existing repository and create a clone of the target repository, so we could let our colleague access this code to add something to it.
💡 We can go to GitHub again, open our repository, and use the clone option We could simply use the code in it, basically clone our GitHub remote repository
git clone <the code in clone option in the GitHub interface>
- The Fetch command downloads commit files and refs from a remote repository into your local repository.
💡 Fetching is what you do when you want to see what everybody else has been working on.
git fetch
- Pull request: is a Git command that allows you to download and integrate changes from a remote repository into your local repository. This command fetches the changes and then merges them into the current branch. It is a convenient way to keep your local repository up-to-date with the changes made by other contributors to the remote repository.
git pull <remote> <branch>
Replace <remote> with the name of the remote repository you want to pull changes from (usually "origin"), and <branch> with the name of the branch you want to merge changes into. For example:
git pull origin master
This command will fetch and download content from the "master" branch of the "origin" remote repository and immediately update the local repository to match that content.
- Git *add :* command adds new or changed files in your working directory to the Git staging area. git add is an important command - without it, no git commit would ever do anything.
git add <file name>
# When you want to add all the changes that were made in the fils
git add .
Conclusion
GitHub is an essential tool for developers who want to collaborate on code and manage their projects. It provides a powerful set of features that enable developers to work together, track changes, and manage their codebase over time. By following the tips in this guide, you can make the most of GitHub and build a thriving community of developers around your projects.
Top comments (0)