Git and GitHub
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
Copied!git config --system git config --global git config --local
Configure user name email for git
Copied!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
Command | Explanation |
---|---|
$ git init | Initialize 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
Command | Explanation |
---|---|
git clone <url> | Git clone is used to clone a remote repository into a local workspace |
git push | Git push is used to push commits from your local repo to a remote repo |
git pull | Git pull is used for fetch the newest updates from a remote repository |
$ git branch | Used 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 -abort | If there are merge conflicts (meaning files are incompatible). --abort can be used to abort the merge action |
$ git log --graph --oneline | This shows a summarize view of the commit history for a repository. |
Show the difference in the tracked files
Command | Explanation |
---|---|
git show | git show is used to show the changes in the head of master commit |
git diff | git diff is used to show the difference in the untracked files |
git diff staged | git diff is used to show the difference in the tracked files |
$ git diff <commit ID> | show difference in the commit |
git clone URL | Git clone is used to cone a remote repository into a local workspace |
git push | Git push is used to push commits from your local repo to a remote repo |
git pull | Git pull is used to fetch the newest updates from a remote repository |
git remote | Lists remote repos |
git remote -v | List remote repos verbosely |
git remote show <name> | Describes a single remote repo |
git remote update | Fetches the most up-to-date objects |
git fetch | Downloads specific objects |
git branch -f | Lists remote branches: can be combined with other branch arguments to manage remote branches |
git log -p | Produces patch text |
git add -p | Allows a user to interactively review patches to add to the current commit |
git mv | Similar to the Linux 'mv' command, this moves a file |
git rm | Similarly to the Linux 'rm' command, this deletes, or removes a file |
push existing repository from the command line
Copied!git remote add origin https://github.com/NepOrganics/nep-org-dashboard.git git branch -M main git push -u origin main