Sunday, February 5, 2012

git cheat sheet

# configuration stuff
    git config --global alias.co checkout
    git config --global core.editor "gvim -f"

# initialize a repository
    git init

# edit file to change what files are excluded from the git repository
    vi .gitignore

# add files that will be checked in
    [in this case, add all files not excluded in .gitignore]
    git add .

# see what files were modified, added to be commited, and what's not tracked
    git status

# commit changes to local repository
    git commit -m "Comments on changes. ..."

# committing all modifications to existing files
    git commit -a -m "Comments on changes. ..."

# show committed changes
    git log

# checkout the local repository version and overwrite any changes
    git checkout -f

# checkout an old version [the period will checkout all the files]
    git log <-- to find the version you want (get the hastag)
    git checkout <hashtag> .
# create a new branch, and switch to it
    git checkout -b 'new branch name'

# switch to master branch
    git checkout master

# merge one branch with another
    git merge <branch name>
 
# list existing and current branch
    git branch

# update your git changes onto another remote repository
    (you should have created a repository with the same name first)
    git remote add origin git@github.com:<username>/repository_name
    git push origin master
 
# remove a file and also tell git to remove it
    git rm filename

No comments:

Post a Comment