Git basics for day to day work

Welcome to Git basics!
This is a very basic touch up on everyday git usage.
Git is a Distributed Version Control System (DVCS), created by Linus Torvalds, primarily to address collaboration issues.

I. CLONE COMMANDS: git clone

  1. Clone a repository into a new directory

    1
    $ git clone <URL>
  2. Clone a repository into a new custom directory myApp

    1
    $ git clone <URL> myApp
  3. Clone a specific branch develop

    1
    $ git clone -b develop <URL>
  4. Create a shallow clone with a history truncated to the specified number of commits

    1
    $ git clone <URL> --depth=2
  5. Create a shallow clone with a history after the specified time.

    1
    $ git clone <URL> --shallow-since=yyyy-mm-dd
  6. Clone by providing credentials in-line

    1
    $ git clone <protocol>://<username>:password@<domain>/repo-name.git --shallow-since=yyyy-mm-dd

In the above example,

  • protocol can be : https, git, ssh, ftp
  • username and password are the credentials that has access to clone this repository.
  • domain is the git host. Ex. github or bitbucket or gitlab, etc.




II. CHECKOUT COMMANDS: git checkouy

Checking for modifications done in local

1
$ git status

Adding your locally changed files for staging

To add a specific file:

1
$ git add <file-path>

To add all the files at once:

1
2
3
$ git add --all
# OR
$ git add .

Committing the changes to local repository

1
$ git commit -m 'my commit message'

Pushing the changes to remote

1
2
3
$ git push
# OR
$ git push origin master

Pulling the latest changes from remote

1
$ git pull