Git is a free and open source distributed version control system...
2 steps to register your changes
git add files.txt
git commit -m "a helpful commit message"
"If you want to build [git] on Windows: Don't."
Important since Github uses email to identify user (unless using ssh)
# configure the user which will be used by git # Of course you should use your name git config --global user.name "Example Surname" # Same for the email address git config --global user.email "firstname.lastname@example.org"
git init awesome-project
cd ~/awesome-project git init
git clone link/to/remote
Specifies intentionally untracked files to ignore
cd awesome-project vim .gitignore
# a comment .to-exclude !include-this.txt
Complete pattern guide here: http://git-scm.com/docs/gitignore
Committed files are not automatically removed. Use this to remove files from git repo:
git rm -r --cached awesome-file
# assuming you have a repo with changes made to it # this shows files that have been changed, and the status of stage git status # add all files to the stage git add . # commit the changes to local repo git commit -m "a message"
# show git log git log # this is what the output looks like commit bcf7bd065199c1e79c8dcc57a9518bd53dec6da5 Author: Sushant Hiray < email@example.com> Date: Tue Apr 8 17:41:14 2013 +0530 started adding files for tomorrow
--oneline- give single line log
-N- give last N commits
A remote is a URL to a remote server where code lives. Default remote is called origin
# add a new remote git remote add < remote> < link> # show all remotes git remote -v # fetches the code and merges it into your working directory git pull < remote> < branch> # fetches the code but does not merge it into your working directory git fetch < remote> < branch> # push my committed changes to remote and remember the upstread branch git push -u origin master
# SSH git clone firstname.lastname@example.org:wncc/wncc.github.io.git # HTTPS git clone https://github.com/wncc/wncc.github.io.git
# because coding while drunk is bad for you git commit -m "my boss is a dick"
# thank god for git git commit --amend -m "my boss is a fat dick"
git log -- filename
# Revert to a previous commit by SHA-1 hash git reset --hard < hash> # or simply undo the last commit git reset --hard HEAD^
# tags are used to mark specific points in history # list all tags git tag # add a new tag git tag -a "v1.0" # or add a tag for any commit git tag -a "v1.0" < hash> # push tags to remote git push --tag
# create a new branch git branch branch-name # list all branches in the current repository git branch # switch to an existing branch git checkout branch-name # create a branch and switch to it git checkout -b branch-name # delete a branch git branch -d branch-name # merge two branches (source into target) (make sure to be on target) git merge source
# git is smart, but not really. when same line is changed more # than once at the same time, conflicts can arise # this is what lines with conflicts look like <<<<<<< HEAD This is what my local repo has. ======= This is what someone else did. >>>>>>> 0c7ac2ab7ab93366fb662e8292706c084001fb31 # manually select what to keep, commit and push!
vim ~/.bashrc # git alias gs='git status' alias ga='git add' alias gc='git commit' alias gp='git push $1 $1' # saves a gazillion keystrokes # for those who live on the edge alias yolo = 'git commit -am "TAG" && git push -f origin master'