Basic git commands

Git is a open-source code version control tool, here are some basic commands to get you going.

BASIC STAGE & COMMIT
Make the current directory a git repository: $ git init
Add files to the repository ready for the next commit: $ git add .
Add/delete files to the repository ready for the next commit: git add . -A
Commit the files with a comment: $ git commit -m "initial commit"
Stage & commit at the same time: $ git commit -am 'update to index.php'
Sync to a git repo (see below): git push origin master
Force commit to a git repo (see below): git push origin +master
Output history of commits: $ git log
Output history of commits: $ git log --graph
Revert to a previous commit: git checkout filename

MANAGING BRANCHES
List current branches: $ git branch
Create new branch: $ git branch newBranchName
Switch to a branch: $ git checkout newBranchName
Stage changes to the new branch $ git add .
Commit changes to the new branch $ git commit -m 'The Kiler Feature added'
Switch back to the master branch $ git checkout master
And merge: $ git merge newBranchName
And delete the old branch: $ git branch -d newBranchName

SETTING UP GITHUB
A. Generate a key on the local machine:
$ ssh-keygen -t rsa -C "an@emailaddress.co.uk"
B. The type a password & use the default filename
C. Then type a password & use the default filename
D. Save the ssh key to github
E. Then test the connection: $ ssh git@github.com

WORKING WITH GITHUB
Clone a remote repository:
git clone git@github.com:anthillsocial/leaflet-multi-map.git
Link a local with a remote repository:
git remote add origin git@github.com:anthillsocial/leaflet-multi-map.git
Upload to the remote repository: $ git push origin master
Sync with the remote repository: $ git pull

GOOD TUTORIALS
General intro to git: http://net.tutsplus.com/tutorials/other/easy-version-control-with-git/
Using submodules: http://git-scm.com/book/en/Git-Tools-Submodules

Comments

Post new comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h2> <h4> <img> <div> <table> <tr> <td> <pre>
  • Lines and paragraphs break automatically.
  • Insert image: [img:node_id align=(left|right) size=(|fullLA|fullPreview|fullSQ|halfLA|halfPO|halfSQ|thirdSQ) action=(popup|link|frame) url=url style="margin:10px;" title=text description=text]

More information about formatting options

 
info@theanthillsocial.co.uk XHTML 1.0 Strict CSS2 WAI