GIT
Git practices and commands
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
Commands
git init
Initialises a new Git repository in the current directory
$ mkdir railsapp
$ cd railsapp
$ git init
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
git status
Shows the current state of your project
$ git status
git log
Shows the the history of all commits made in your project
$ git log
git remote
Links your local project to a remote repository like GitHub
$ git remote add origin https://github.com/username/projectname.git
git commit
Commit staged changes with a commit message
$ git add .
$ git commit -m "Update files"
git push
Push changes to a git repository
$ git push origin main/master
git pull
Pulls the latest changes from the online repository to your local project
$ git pull
git branch
list branches, create branch, and switch to it
$ git branch
$ git branch feature-login
git fetch
Retrieve data from a remote repository without merging chnages
$ git remote add origin <url>
git checkout
Switch to the specified branch
$ git checkout feature-login
git merge
Merge the specified branch into the current branch
$ git checkout main
$ git merge feature-login
git reset
Reset the current branch to the specified commit
$ git log --oneline
$ git reset --hard last-commit-hash
git clone
Copies an existing repository from GitHub to your local system
$ git clone https://github.com/username/project.git