Home > git > git commands – Notes

git commands – Notes

git commands that I normally forget 🙂

$ git init
$ git add <file>
$ git commit -m "commit message"
$ git rm --cached <file>
$ git status
$ git log
$ git branch
$ git branch <branch name> # To create a new branch
$ git checkout  # To switch to a different branch
$ git log --graph --decorate --pretty=oneline --abbrev-commit
# To create a command alias
$ git config <level> alias.<alias name> '<your sequence of git commands>' 
# eg to create git tree command
$ git config --global alias.tree 'log --graph --decorate --pretty=oneline --abbrev-commit'
$ git tree
$ git tag -d <tag name> # To delete a tag
$ git branch -d  <branch name> # To delete a branch

Update
Getting more and more used to working with git. A few more commands that are useful.

$ git rm -r --cached <dir> # To stop tracking a directory that was already committed.
                           # Does not delete the directory.
$ git update-index --assume-unchanged path/to/file.txt # To stop tracking future changes to a file.

Merging a branch. Assumption that it is a clean branch i.e. everything has been committed.

$ git branch
master
feature_1
*feature_2
$ git checkout feature_1
$ git merge feature_2

Deleting Remote and local branches.

$ git branch -d <branch>
warning: deleting branch '<branch>' that has been merged to
         'refs/remotes/origin/<branch>', but not yet merged to HEAD.
Deleted branch <branch>
$  git push origin --delete<branch>
 - [deleted]         <branch>

Tagging

# Adding
$ git tag -a v0.1 -m "Initial release 0.1"
# Deleting a local tag
$ git tag -d v0.1
# Deleting a remote tag (after you deleted it locally).
$ git push origin :refs/tags/v0.1

Source
http://stackoverflow.com/questions/1329291/ignoring-an-already-checked-in-directorys-contents
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
https://nathanhoad.net/how-to-delete-a-remote-git-tag

Advertisements
Categories: git
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: