← Back to Note

Git and GitHub

Prakash Pun

Prakash Pun - December 24, 2022

4 min read

Git is a free and open-source distributed Version Control System (VCS) design to handle everything from small to large project with speed and efficiency.

Github is a collaboration platform built on top of git

To get started with Git download git from

Configuring Git

git config --system git config --global git config --local

Configure user name email for git

git config --global user.name "<username>" git config --global user.email "<useremail>" git config --global core.editor "atom --wait" git config --global color.ui true git config --list

Let's write some git commands

CommandExplanation
$ git initInitialize git in your directory
$ git add <filename>Add changes to the staging index
$ git commit -m "<Commit message>"Commit the changes to the git repository
  • Commit Message
  • A short -single summary (less than 50 characters)
  • Good if the commit is in present tense
CommandExplanation
git clone <url>Git clone is used to clone a remote repository into a local workspace
git pushGit push is used to push commits from your local repo to a remote repo
git pullGit pull is used for fetch the newest updates from a remote repository
$ git branchUsed to manage branches
$ git branch <branch name>Creates the branch
$ git branch -d "<branch name>"Deletes the branch
$ git branch -D "<branch name>"Forcibly deletes the branch
$ git checkout "<branch name>"Switches to a branch
$ git checkout -b "<branch name>"Creates a new branch and switches to it.
$ git merge "<branch name>"Merge joins branches together
$ git merge -abortIf there are merge conflicts (meaning files are incompatible). --abort can be used to abort the merge action
$ git log --graph --onelineThis shows a summarize view of the commit history for a repository.

Show the difference in the tracked files

CommandExplanation
git showgit show is used to show the changes in the head of master commit
git diffgit diff is used to show the difference in the untracked files
git diff stagedgit diff is used to show the difference in the tracked files
$ git diff <commit ID>show difference in the commit
git clone URLGit clone is used to cone a remote repository into a local workspace
git pushGit push is used to push commits from your local repo to a remote repo
git pullGit pull is used to fetch the newest updates from a remote repository
git remoteLists remote repos
git remote -vList remote repos verbosely
git remote show <name>Describes a single remote repo
git remote updateFetches the most up-to-date objects
git fetchDownloads specific objects
git branch -fLists remote branches: can be combined with other branch arguments to manage remote branches
git log -pProduces patch text
git add -pAllows a user to interactively review patches to add to the current commit
git mvSimilar to the Linux 'mv' command, this moves a file
git rmSimilarly to the Linux 'rm' command, this deletes, or removes a file

push existing repository from the command line

git remote add origin https://github.com/NepOrganics/nep-org-dashboard.git git branch -M main git push -u origin main

Thank You 😁😁😁