Stage or Commit and clone an existing project using Git

What is Git?

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.

  1. On Windows, select the first option, use Git from Git Bash only, during the installation
  2. 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
  3. Check your Git version by using following command
  4. $ git –version
  5. In order to display the Git help screen type the following command

usage: git [–version] [–help] [-C <path>] [-c name=value]

[–exec-path[=<path>]] [–html-path] [–man-path] [–info-path]

[-p | –paginate | –no-pager] [–no-replace-objects] [–bare]

[–git-dir=<path>] [–work-tree=<path>] [–namespace=<name>]

<command> [<args>]

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:

Make a local clone that borrows from the current directory, without checking things out:

Clone from upstream while borrowing from an existing local directory:

Create a bare repository to publish your changes to the public:

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

    1. Open Git Bash.
    2. Change the current working directory to your local project.
    3. Initialize the local directory as a Git repository.

    1. Add the files in your new local repository. This stages them for the first commit.

    1. Commit the files that you’ve staged in your local repository.

    1. At the top of your GitHub repository’s Quick Setup page, click  to copy the remote repository URL.
using git

Github Repository URL

    1. In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

    1. Push the changes in your local repository to GitHub.

Video Tutorial

Conclusion

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.

Leave a Reply

Your email address will not be published. Required fields are marked *