Git is a fast distributed revision control system.
What is in this article?
This article is designed to be understandable by windows user or someone with basic UNIX command-line skills, but no previous knowledge of Git. It’s an introductory video which elaborate the basic commands of Git. Repositories and branches and exploring Git history explain how to fetch and study a project using git—read our article to know more about git and so on.
This article covers the installation, cloning from a remote repository, create repository on GitHub, add and commit to remote GitHub repository. Video tutorial shows you step by step activities performed. The recommendation for reader is to installat Git Bash because we will use Git Bash in our tutorial.
Download and Install Git
Download Git from “https://git-scm.com/downloads” and install it. A GUI client is also available if you want to use once you are done with command line git Bash or git shell.
On Windows, select the first option, use Git from Git Bash only, during the installation
To run Git on Windows, use the provided git bash or git shell application to open a command line with Git integration. Git get integrated as a default terminal of both Linux and MacOS
Check your Git version by using following command
$ git –version
In order to display the Git help screen type the following command
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
‘git help -a’ and ‘git help -g’ list available subcommands and some
concept guides. See ‘git help <command>’ or ‘git help <concept>’
to read about a specific subcommand or concept.
Clone a repository into a new directory using Git Bash or Console
Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository, and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.
Clone from upstream:
$ git clone git://git.kernel.org/pub/scm/.../ myrepository.git myrepository
$ cd myrepository
Make a local clone that borrows from the current directory, without checking things out:
Adding an existing project to GitHub using the command line
Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can
Add these files after your project has been pushed to GitHub using Git Bash
Open Git Bash.
Change the current working directory to your local project.
Initialize the local directory as a Git repository.
$ git init
Add the files in your new local repository. This stages them for the first commit.
$ git add .
# Adds the files in the local repository and stages them for commit.
# To unstage a file, use 'git reset HEAD YOUR-FILE'.
Commit the files that you’ve staged in your local repository.
$ git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a
# remote repository. To remove this commit and modify the file,
# use 'git reset --soft HEAD~1' and commit and add the file again.
At the top of your GitHub repository’s Quick Setup page, click to copy the remote repository URL.
Github Repository URL
In the Command prompt, add the URL for the remote repository where your local repository will be pushed.
$ git remote add origin
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
Push the changes in your local repository to GitHub.
$ git push origin master
# Pushes the changes in your local repository up to the remote repository
# you specified as the origin
In this tutorial you have learned to download and install Git, clone a remote repository in your local directory, stage your project and commit your project files in a remote repository. A video tutorial showing step by step activities is also available. In my next tutorial, you will learn how to create a local repository and add files to stage and commit to repository.
Please leave your feedback and comments below. Follow us on twitter, like our Facebook page or subscribe to our newsletter to stay updated on upcoming tutorials.