View on GitHub

Matt's homepage

Bookmark this to keep an eye on new things I am learning.

GIT

Git practices and commands

Return Home

Practices

.GitIgnore

Use a .gitignore file to implicity include or exclude files from Git

# exclude these
/node_modules
/config/*.json
/dist
/public/custom/pictures
/public/custom

# include this specifically
!/public/custom/custom.css

# Empty folders with only a .keep file are included. Good to retain folder structure
!.keep

^ back to top ^

Commands

git init

Initialises a new Git repository in the current directory

$ mkdir railsapp  
$ cd railsapp  
$ git init

^ back to top ^

git add

Adds state changes in the current director for staging

$ echo "README.md" >> ADE.md  
$ echo "app.rb" >> README.md  
$ git add README.md

^ back to top ^

git status

Shows the current state of your project

$ git status

^ back to top ^

git log

Shows the the history of all commits made in your project

$ git log

^ back to top ^

git remote

Links your local project to a remote repository like GitHub

$ git remote add origin https://github.com/username/projectname.git

^ back to top ^

git commit

Commit staged changes with a commit message

$ git add .  
$ git commit -m "Update files"  

^ back to top ^

git push

Push changes to a git repository

$ git push origin main/master

^ back to top ^

git pull

Pulls the latest changes from the online repository to your local project

$ git pull

^ back to top ^

git branch

list branches, create branch, and switch to it

$ git branch  
$ git branch feature-login

^ back to top ^

git fetch

Retrieve data from a remote repository without merging chnages

$ git remote add origin <url>

^ back to top ^

git checkout

Switch to the specified branch

$ git checkout feature-login

^ back to top ^

git merge

Merge the specified branch into the current branch

$ git checkout main  
$ git merge feature-login

^ back to top ^

git reset

Reset the current branch to the specified commit

$ git log --oneline  
$ git reset --hard last-commit-hash

^ back to top ^

git clone

Copies an existing repository from GitHub to your local system

$ git clone https://github.com/username/project.git

^ back to top ^