Özgün Koyun Özgün Koyun

A few git tips

  git

Spell checking

To enable spell checking with git-gui, Install aspell and aspell-en packages.

$ sudo pacman -S aspell aspell-en

Colorful outputs

Over Here

swap files

To ignore all “.swp” files add the following line to your “.git/info/exclude” file.

*.swp

.gitignore

My .gitignore file.

tmp/**/*
log/*.log
db/*.sqlite3
db/*.sql
db/schema.rb
config/database.yml
config/deploy.rb
.loadpath
.project
.DS_Store
cache/views/*
test/fixtures/settings.yml

Initializing a bare repo

$ mkdir myapp.git
$ cd myapp.git
$ git --bare init

Creating a remote branch

$ git checkout -b mynewbranch
$ git push origin mynewbranch

Branches

Playing with branches(create, switch, merge)

$ git branch #Display local branches
$ git checkout -b newbranchname # Create a new branch and switch to it.
$ git checkout master # Switch back to master
$ git checkout newbranchname # Switch back to newbranchname
$ git merge master #Merge master branch into newbranchname
$ git checkout newbranchname # Switch back to newbranchname

Adding a new remote repository

$ git remote add origin ssh://[email protected]/home/user/repositories/myapp.git/
$ git remote add origin file:///home/user/repositories/myapp.git/

Undo(revert) committed changes

$ touch file.txt
$ git add file.txt
$ git commit -a -m "Adding file.txt"
$ git log # ==> commit 9972713b5677302580959644aebd33196eefa38e 
$ git-revert 9972713b5677302580959644aebd33196eefa38e
$ git status

To revert the most recent commit

$ git revert HEAD

Lets say you changed some files in your working tree and you haven’t committed yet, but suddenly you decide that it was a big mistake and you want to go back to last committed state. You could undo uncommitted changes with the following command.

$ git reset --hard HEAD