To understand GitHub, one has to first have an understanding of Git. So in this post we will talk on What is GitHub? Git is an open-source version system that is an initiative of Linus Torvalds—he who created Linux. Git is analogous to other version control systems—Subversion, CVS, and Mercurial to call a couple of .
So, Git may be a version system , but what does that mean? When developers create something (an app, for instance), they create constant changes to the code, releasing new versions up to and after the primary official (non-beta) release.
Version control systems keep these revisions straight, storing the modifications during a central repository. this enables developers to simply collaborate, as they will download a replacement version of the software, make changes, and upload the most recent revision. Every developer can see these new changes, download them, and contribute.
Similarly, people that don’t have anything to try to to with the event of a project can still download the files and use them. Most Linux users should be conversant in this process. As, using Git, Subversion, or another similar method is pretty common for downloading useful files. Specially, in preparation for compiling a program from ASCII text file (a rather common practice for Linux geeks).
Git is that the preferred version system of most developers, since it’s multiple advantages over the opposite systems available. It stores file changes more efficiently and ensures file integrity better. If you’re curious about knowing the small print , the Git Basics page features a thorough explanation on how Git works.
We know that Git is a version system, similar but better than the various alternatives available. So, what makes GitHub so special? Git may be a command-line tool, but the middle around which all things involving Git revolve is that the hub—GitHub.com—where developers store their projects and network with compatible people.
Let’s re-evaluate a couple of of the most reasons that geeks wish to use GitHub, and learn some terminology along the way.
Repository : repository or “repo” may be a location where all the files for a specific project are stored. Each project has its own repo, and you’ll access it with a singular URL.
Forking a Repo
“Forking” is once you create a replacement project based off of another project that already exists. This is often a tremendous feature that vastly encourages the further development of programs and other projects. Also, if you discover a project on GitHub that you’d wish to contribute to, you’ll fork the repo, make the changes you’d like, and release the revised project as a replacement repo. Thus, if the first repository that you simply fork to make your new project updates, you’ll easily add those updates to your current fork.
This operation helps you to save the changes in your file. When you commit a file, you should always provide the message, just to keep in the mind the changes done by you. Though this message is not compulsory but it is always recommend. So, that it can differentiate the various versions or commits you have done so far to your repository. These commit messages maintain the history of changes which in turn help other contributors to understand the file better. Now let’s make our first commit, follow the below steps:
- Click on “readme- changes” file which we have just created.
- Click on the “edit” or a pencil icon in the righmost corner of the file.
- Once you click on that, an editor will open where you can type in the changes or anything.
- Write a commit message which identifies your changes.
- Click commit changes in the end.
You’ve forked a repository, made an excellent revision to the project, and need it to be recognized by the first developers. You’ll do so by creating a pull request. The authors of the first repository can see your work, then choose whether or to not accept it into the official project. Whenever you issue a pull request, GitHub provides an ideal medium for you and therefore the main project’s maintainer to speak .
Project revisions are often discussed publicly. So, a mass of experts can contribute knowledge and collaborate to advance a project forward. Before the arrival of GitHub, developers curious about contributing to a project would usually got to find some means of contacting the authors—probably by email—and then convince them that they will be trusted and their contribution is legit.
When multiple people collaborate on a project, it’s hard to stay track revisions—who changed what, when, and where those files are stored. GitHub takes care of this problem by also keeping track of all the changes pushed to the repository.
GitHub Isn’t only for Developers
All these points mentioned how GitHub is right for programmers may have you ever believing that they’re the sole ones who will find it useful. Although it’s tons less common, you’ll actually use GitHub for any sorts of files. If you’ve got a team that’s constantly making changes to a word document, for example, you’ll use GitHub as your version system . This practice isn’t common, since there are better alternatives in most cases, but it’s something to stay in mind.
Also, now that you simply know what GitHub is all about, are you able to start? Head over to GitHub.com and make certain to see out their help pages after signing up.
A List of Git Commands
Create a new Git repository from an existing directory thus:
git init [directory]
Clone a repository (local or remote via HTTP/SSH):
git clone [repo / URL]
Clone a repository into a specified folder on your local machine:
git clone [repo / URL] [folder]
Attach an author name to all commits that will appear in the version history:
git config --global user.name "[your_name]"
Attach an email address also to all commits by the current user:
git config --global user.email "[email_address]"
Apply Git’s automatic command line coloring which helps you keep track and also revise repository changes:
git config --global color.ui auto
Create a shortcut (alias) for a Git command:
git config --global alias.[alias_name] [git_command]
Set a default text editor:
git config --system core.editor [text_editor]
Also, open Git’s global configuration file:
git config --global --edit
Show the state of the current directory (list staged, unstaged, and untracked files):
List the commit history of the current branch:
List all commits from all branches:
git log --all
Compare two branches by showing which commits from the first branch are missing from the second branch and thus show:
git log [branch1]..[branch2]
Examine the difference between the working directory and the index:
Explore the difference between the last commit and the index:
get diff --cached
See the difference between the last commit and the working directory:
get diff HEAD
Display the content and also the metadata of an object (blob, tree, tag or commit):
git show [object]
List all branches in the repository:
List all remote branches:
git branch -aa
Create a new branch under a particular name:
git branch [branch]
Switch to a branch under a specific name :
git checkout [branch]
Delete a local branch:
git branch -d [branch]
Rename a branch you are currently working in:
git branch -m [new_branch_name]
Merge a specific branch with the current branch:
git merge [branch]
Stage changes for the next commit:
git add [file/directory]
Thus, Stage everything in the directory for an initial commit:
git add .
Commit staged snapshots in the version history with also a descriptive message included in the command:
git commit -m "[descriptive_message]"
Undo changes in a file or directory and also create a new commit with the git revert command:
git revert [file/directory]
Unstage a file without overwriting changes thus :
git reset [file]
Undo any changes introduced after the specified commit:
git reset [commit]
Show untracked files which will be removed when you run
git clean (do a dry run):
git clean -n
Remove untracked files:
git clean -f
Replace the last commit with a combination of the staged changes and the last commit combined:
git commit --amend
Create a new connection to a remote repository (give it a name to serve as a shortcut to the URL):
git remote add [name] [URL]
Thus, to Fetch a branch from a remote repository:
git fetch [remote_repo] [branch]
Fetch a repository and also merge it with the local copy:
git pull [remote_repo]
Also, Push a branch to a remote repository with all its commits and objects:
git push [remote_repo] [branch]
SUMMING UP !!!
In this post, we have thus, gone through the journey of GitHub. Through the basic nitty-gritty to the most important functionalities and terms. Also, if you have any queries and/or doubts or you face any problem while going through this. Or maybe doing your work on GitHub, then, feel free to come in touch with me. You can also post the things in comments.
Till then go through the other posts of mine here. Until then good-bye !!