Preview:
which git

git version

brew install git

brew upgrade git

# Git is in the root of the folder and tracks all the changes
# A commit is like a save point
# Modified -> Staging -> Committed

git init {Start a git repo in a folder}

git status {Status of the files in the staging area}

git add file_name {Add to staging area}

git rm --cashed file_name {Remove file from staging area}

git add . {Add all files to the staging area}

git commit -m "descriptive message"

git log {History of commits}

git log --oneline

git checkout commit_ID {Check out this save point}

git checkout master {Return to master save point}

git revert commit_ID { press Shift + : and enter wq to get out of the screen; Revert the commint for that commit_ID}

git reset commit_ID {You can re-commit the files}

git reset commit_ID --hard {Files after this commit are deleted}

git branch -b branch_name {Create a new branch}

git branch -a {List of all the branches and the current branch is shown with *}

git checkout branch_name {To switch the branch}
                          
git branch -D branch_name {Go to master branch to delete an un-merged branch}
                          
git merge branch_name {Merge a branch to a master branch}
                          
touch .gitignore { .gitignore file is created}
   
                          
                          
To push new branch and make PR

git push -u origin dev_branch 



**GitHub**
  
Create a new repository on GitHub
  
git push {https://github.com} master
          
git remote add origin {https://github.com}          
          
git push origin master


or create a new repository on the command line
echo "# unity-app" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M master
git remote add origin https://github.com/hackstrap/unity-app.git
git push -u origin master


push an existing repository from the command line
git remote add origin https://github.com/hackstrap/unity-app.git
git branch -M master
git push -u origin master


To Clone Repos:
Open Terminal.
Change to the location where you want the cloned directory (Not required to create the folder)
Type git clone, and then paste the URL you copied earlier.
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY                       
Press Enter to create your local clone.

#To Check Alias          
git remote -v {Check Alias}

On master branch:
$ git pull origin master {Be all up-to-date}          

To update local branch and create PR                     
Note: Don't merge with master branch locally
$ git push origin branch_name

Then -> Compare & pull request and create a pull request. You can request a review.
Admin can 'Merge pull request' with a comment




To Fork a Repo

Go to where you want to clone (cd)

Clone a Repo

New pull request on the original repo


.gitignore list for Python Projects

https://gist.github.com/GhostofGoes/94580e76cd251972b15b4821c8a06f59


How to change the URI (URL) for a remote Git repository?
git remote -v
# View existing remotes
# origin  https://github.com/user/repo.git (fetch)
# origin  https://github.com/user/repo.git (push)

git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL

git remote -v
# Verify new remote URL
# origin  https://github.com/user/repo2.git (fetch)
# origin  https://github.com/user/repo2.git (push)
           



Update chnages from master branch and then merge it with local branch updates:

git checkout master              
           
git pull origin master   
                          
git merge branch_name                          
                          
git status                             
                         
git push origin master  



downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter