Install GIT
This is a step-by-step guide to install Git on Mac
This post will guide you through step-by-step instruction to install git on Mac system
Installing GIT on Mac
- Install Install Java on Mac using brew is a simple process. You need to have
brew
installed on your system as a pre-requisite. You can install brew from here Install git as
brew install git
Verfiy git installation
Pavans-MacBook-Pro:pavanpkulkarni.com pavanpkulkarni$ git version git version 2.15.1
Here are some git basic commands:
---------------------------------
Clone a specific branch:
---------------------------------
git clone -b pavan
---------------------------------
sync local branch with master:
---------------------------------
git checkout master
git pull
git checkout pavan
git merge master
------------------------------
merge local_branch to master
------------------------------
git checkout -f master
git merge local_branch
git push origin master
----------
uncommit
----------
git reset --hard HEAD~1 -> one commit removed
------------
update fork
------------
git remote add upstream https://github.com/<username>/repo.git
git fetch upstream
git checkout master
git merge upstream/master
-------
stash
-------
git stash
git stash pop
-------------------------------
Add SSH Key to you Git Profile
-------------------------------
1. Generate a new SSH key for you system
ssh-keygen -t rsa -b 4096
pbcopy < ~/.ssh/id_rsa.pub
2. Add ssh public key to SSH in git console (Settings -> SSH and PGP Keys -> Select New SSH Key)
3. New clone (not required if already cloned)
git clone git@github.com:pavanpkulkarni/repo.git
4. upstream
git remote add upstream git@github.com:pavanpkulkarni/repo.git
---------------
Set remote URL
---------------
1. git remote set-url origin git@github.com:username/repo.git
2. git remote set-url upstream git@github.com:username/repo.git
3. git remote -v
origin git@github.com:username/repo.git (fetch)
origin git@github.com:username/repo.git (push)
upstream git@github.com:username/repo.git (fetch)
upstream git@github.com:username/repo.git (push)
-------------------
word wrap for diff
-------------------
GIT_PAGER='' git diff
-------------------
Delete Remote Branch
--------------------
git push origin --delete <branch_name>
-------------------
Delete Local Branch
-------------------
git branch -D <branch_name>
----------------------------
Force Push to Remote Branch
----------------------------
git push --force origin branch_name:master
-------------------
add remote branch
-------------------
git fetch origin
git checkout --track origin/<remote_branch_name>
Share this post
Twitter
Google+
Facebook
LinkedIn
Email