HOWTO: Quick Git Guide
Posted: Fri Feb 20, 2015 9:21 am
This was originally a post by dkeg, I copy-paste it here to have GIT stuffin one place. Thanks Drew for the nice tutorial :)
dkeg wrote:disclaimer, I'm sure Joe would have a more proper tutorial for this.
Generally speaking ... we're looking at two separate things here, using git locally and with a service such as GitHub or Bitbucket.
Using locally:initialize the directory, add the items, commitCode: Select all
sudo apt-get install git
First things first, create you ssh keyCode: Select all
cd /dir/for/git git init git add -A #above is all to add all items. You can add specific items too git add file1 file2 file3 git commit -m 'm is for message, add your message here' git status #check current status
Copy the public key and use that for your key in GitHub/BitbucketCode: Select all
ssh keygen -t rsa "email"
Connecting with a remote server. Pretty much the same as above, of course we need to specify our remote locationCode: Select all
cd ~/.ssh <editor> id_rsa.pub
When we push origin master, we push up to our remote GitHub account.Code: Select all
cd /dir/for/git git remote add origin [email protected]:gituser/reponame.git git push origin master
When you are happy with you current state, you can create a branch, and work off the branch.Move to the new branchCode: Select all
git branch <branchname>
Create and move to all in oneCode: Select all
git checkout <branchname>
Now you can do all your work on the branch, when you're happy, commit and merge it with masterCode: Select all
git checkout -b <branchname>
You can either keep the branch or deleteCode: Select all
git commit -m 'commit message' git checkout master # check the current working branch git branch git merge <branchname>
For cloning a repoCode: Select all
git branch -d <branchname>
To help keep my clones organized I create a git directoryCode: Select all
git clone [email protected]:gituser/reponame.git cd reponame # track it git remote add upstream git://github.com/gituser/reponame.git git fetch upstream # I generally do git pull
Code: Select all
mkdir git cd git git clone ..... be happy and organized
Other cool stuffMore disclaimer, please don't by shy about questions. Again, I am not a pro at this, its mainly from what I've picked up from personal use. There is obviously so much more that can be done, and possibly better ways to do stuff. For my configs and such I generally don't branch, but when I was coding, I would definitely branch.Code: Select all
git diff git log --graph
Hopefully I didn't leave anything important out.
Edit: IIRC when you add a remote origin,if its added as https, not ssh. You can change that with set-urlCode: Select all
git remote set-url origin [email protected]:gituser/reponame.git