04 Github CheatSheet

04 Github CheatSheet

Github Cheat Sheet

GIT :

Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files.

GITHUB :

GitHub is a web-based Git repository hosting service, for Git repositories maintained by Microsoft

Installation :

GitHub Desktop

GitHub SCM

Configuration :

Configure user information for all local repositories

$ git config --global user.name "[name]"

Sets the name you want attached to your commit transactions

$ git config --global user.email "[email address]"

Sets the email you want attached to your commit transactions

Create Repositories

A new repository can either be created locally, or an existing repository can be cloned. When a repository was initialized locally, you have to push it to GitHub afterwards.

$ git init

The git init command turns an existing directory into a new Git repository inside the folder you are running this command. After using the git init command, link the local repository to an empty GitHub repository using the following command:

$ git remote add origin [url]

To Clone the Repository :

$ git clone [url]

Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits

.gitignore

Sometimes it may be a good idea to exclude files from being tracked with Git. This is typically done in a special file named .gitignore

Branches

Branches are an important part of working with Git. Any commits you make will be made on the branch you’re currently “checked out” to.

Use git status to see which branch that is.

  • Creates a new branch
$ git branch [branch-name]
  • Switches to the specified branch and updates the working directory
$ git switch -c [branch-name]
  • Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation.
$ git merge [branch]
  • Deletes the specified branch
$ git branch -d [branch-name]

Synchronize changes

Synchronize your local repository with the remote repository on GitHub.com

$ git fetch

Downloads all history from the remote tracking branches

$ git merge

Combines remote tracking branches into current local branch

$ git push

Uploads all local branch commits to GitHub

$ git pull

Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull is a combination of git fetch and git merge

Make Changes

$ git log

Lists version history for the current branch

$ git add [file]

Snapshots the file in preparation for versioning

$ git commit -m "[descriptive message]"

Records file snapshots permanently in version history

$ git log --follow [file]

Lists version history for a file, beyond renames (works only for a single file)

$ git diff [first-branch]...[second-branch]

Shows content differences between two branches