Upload
ramya-murugan
View
54
Download
6
Embed Size (px)
Citation preview
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 1/14
git - the simple guidejust a simple guide for getting started with git. no deep shit ;)
Tweet 4,747
by Roger Dudler
credits to @tfnico, @fhd and Namics
this guide in deutsch, español, français, italiano, nederlands, português, русский, türkçe,
ြမနမာ, 日本語, 中文, 한국어 Vietnamese
please report issues on github
setupDownload git for OSX
Download git for Windows
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 2/14
Download git for Linux
create a new repositorycreate a new directory, open it and perform a
git init
to create a new git repository.
checkout a repositorycreate a working copy of a local repository by running the command
git clone /path/to/repository
when using a remote server, your command will be
git clone username@host:/path/to/repository
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 3/14
workflowyour local repository consists of three "trees" maintained by git. the first one is
your Working Directory which holds the actual files. the second one is
the Index which acts as a staging area and finally the HEAD which points
to the last commit you've made.
add & commitYou can propose changes (add it to the Index) using
git add <filename>
git add *
This is the first step in the basic git workflow. To actually commit these
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 4/14
changes use
git commit -m "Commit message"
Now the file is committed to the HEAD, but not in your remote repository yet.
pushing changesYour changes are now in the HEAD of your local working copy. To send those
changes to your remote repository, execute
git push origin master
Change master to whatever branch you want to push your changes to.
If you have not cloned an existing repository and want to connect your
repository to a remote server, you need to add it with
git remote add origin <server>
Now you are able to push your changes to the selected remote server
branching
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 5/14
Branches are used to develop features isolated from each other. The master
branch is the "default" branch when you create a repository. Use other branches
for development and merge them back to the master branch upon completion.
create a new branch named "feature_x" and switch to it using
git checkout -b feature_x
switch back to master
git checkout master
and delete the branch again
git branch -d feature_x
a branch is not available to others unless you push the branch to your remote
repository
git push origin <branch>
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 6/14
update & mergeto update your local repository to the newest commit, execute
git pull
in your working directory to fetch and merge remote changes.
to merge another branch into your active branch (e.g. master), use
git merge <branch>
in both cases git tries to automerge changes. Unfortunately, this is not always
possible and results in conflicts. You are responsible to merge those conflicts
manually by editing the files shown by git. After changing, you need to mark
them as merged with
git add <filename>
before merging changes, you can also preview them by using
git diff <source_branch> <target_branch>
taggingit's recommended to create tags for software releases. this is a known concept,
which also exists in SVN. You can create a new tag named 1.0.0 by executing
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 7/14
git tag 1.0.0 1b2e1d63ff
the 1b2e1d63ff stands for the first 10 characters of the commit id you want to
reference with your tag. You can get the commit id by looking at the...
login its simplest form, you can study repository history using.. git log
You can add a lot of parameters to make the log look like what you want. To
see only the commits of a certain author:
git log --author=bob
To see a very compressed log where each commit is one line:
git log --pretty=oneline
Or mabe you want to see an ASCII art tree of all the branches, decorated with
the names of tags and branches:
git log --graph --oneline --decorate --all
See only which files have changed:
git log --name-status
These are just a few of the possible parameters you can use. For more, see
git log --help
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 8/14
replace local changesIn case you did something wrong (which for sure never happens ;) you can
replace local changes using the command
git checkout -- <filename>
this replaces the changes in your working tree with the last content in HEAD.
Changes already added to the index, as well as new files, will be kept.
If you instead want to drop all your local changes and commits, fetch the latest
history from the server and point your local master branch at it like this
git fetch origin
git reset --hard origin/master
useful hintsbuiltin git GUI
gitk
use colorful git output
git config color.ui true
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 9/14
show log on just one line per commit
git config format.pretty oneline
use interactive adding
git add -i
links & resourcesgraphical clients
GitX (L) (OSX, open source)Tower (OSX)
Source Tree (OSX & Windows, free)GitHub for Mac (OSX, free)GitBox (OSX, App Store)
guides
Git Community BookPro Git
Think like a gitGitHub Help
A Visual Git Guide
get help
Git User Mailing List#git on irc.freenode.net
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 10/14
comments374 Comments git the simple guide Login
Sort by Newest Share ⤤
Join the discussion…
• Reply •
rcn • 5 days ago
so maybe I'm misuderstanding git..but I have a working directory with one file in it, and Imade a branch named "develop" to modify that file which involved breaking it forawhile. however, I just realized that if I git checkout between my master and developbranch, that file is exactly the same in both branches, ie what's the point of making aseparate branch to test changes in if it's modifying the file in my master branch as well?was surprised that happened, maybe I'm doing something wrong?
• Reply •
Seiji Naganuma • 4 days ago> rcn
The way I look at branches is that they are pointers to commits or snapshots youhave made. When you create and checkout the new branch, you're only going tomove the "develop" pointer forward. Once you checkout the master branch,you're moving the "master" pointer each time you make a commit.
To make the master and develop branches the exact same you either had to havemerged the two branches together or mistakenly made changes on the wrongbranch.
One important point to remember is that creating a new branch doesn'tautomatically checkout that branch. You need to run "git branch develop" then"git checkout develop" or run "git checkout b develop".
• Reply •
rcn • 4 days ago> Seiji Naganuma
maybe I accidentally did it without checking out to a different branch, I'mnot sure. So, if I'm in my working directory (the local folder on my actualcomputer) where I initialized git, and I git checkout to a new branch, thenI open and edit my file (in the new branch) in my text editor, save it andexit out..how does git tell the actual local file that it's supposed to havetwo instances? (on two separate branches). In that scenario, the only filethat should have the changes is the one that's in the branch I edited itfrom, correct?
• Reply •
Seiji Naganuma • 3 days ago> rcn
the working directory will look like your branch that youcheckout. So if you do work on Develop and then checkoutMaster, your working directory will change. Git will make surethat there is no uncommitted changes before you check out adifferent branch. The information for the different branches arestored in you .git folder.
• Reply •
Meteor Fury • 6 days ago
Yeah, this is exactly what I needed. Good basic tutorial.
Umer Jafer • 9 days ago
Favorite
Share ›
Share ›
Share ›
Share ›
Share ›
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 11/14
• Reply •
Great Tutorial! Best for anyone coming from SVN or some other repo who don't need nodeep shit ;)
1
• Reply •
sidn • 14 days ago
Awesome tutorial! Thanks a lot! :)
3
• Reply •
lmayorga • 18 days ago
Sorry about thatnew to social media of any sort. Apparently need to work on draggingand dropping.
1
• Reply •
lmayorga • 18 days ago
I'm forever in your debt for providing a bigpicture context for my isolated insights!
4
• Reply •
JAYTECH • 20 days ago
Super Helpful! Thank you so much!
1
• Reply •
Tomas Drozda • 22 days ago
Awesome :)
• Reply •
fasflow • 22 days ago
Thanks a lot for this tuto/memo of git ! I love it !! And what a flatdesign website !*APPLAUSE*
• Reply •
thekngmkr • 22 days ago
Dude... just made my day... no deep shit...ha ha
3
• Reply •
Matt RhysDavies • 22 days ago
Absolutely brilliant thank you. Wish I had found this guide when I was first starting outwith Git!
3
• Reply •
Andy Hidayat • 24 days ago
awesome tutorials... great !!!!
• Reply •
Nick Jacobs • 25 days ago
So, so, so helpful. Git is one of those tools where everything is familiar and yet differentat the same time. Thanks!
• Reply •
akyan • a month ago
really helpful! Thanks!
Neo India • a month ago
Best! You proved it things can be simple and great!
Cheers,Neo
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 12/14
• Reply •
Neo
• Reply •
Haren • a month ago
It is really helpful..... already bookmarked this page.
• Reply •
Jin • a month ago
hi ! i just want to ask what if it is asking me to stash my changes ? what should i do?thanks!
2
• Reply •
Vineeth Reddy • a month ago> Jin
can you be specific when git asked you to stash your changes.
In general, stashing by "git stash" removes all changes from staging area andmodified area and are saved it .git folder. You'll then have a clean slate withoutany changes. You need not worry about all your changes, you can reapply themusing "git stash apply"
1
• Reply •
LudovicHenin • a month ago
Your comments list is insane bud.But what an awesome page. Thanks.
• Reply •
nihat • a month ago
awesome tutorial, thanks!
• Reply •
Allen Stroy • a month ago
Love it! Great simple overview!!!
• Reply •
Phạm Sinh • a month ago
thanks you! great
1
• Reply •
Ivan Lozo • a month ago
great, thank you!
• Reply •
João Carlos Ferreira • a month ago
This is really helpful!Thanks for the post
• Reply •
Shon Feder • a month ago
thank you! I will be referring back often.
1
• Reply •
TweetsOfSumit • a month ago
ha! Good stuff, thanks!
• Reply •
berkapavel • a month ago
really helpful... thank you
• Reply •
ashwin • a month ago
thankssssssss
Joe Dougherty • a month ago
Great guide. I've been on the peripheral of git for a long time, now I need it and thismakes a lot clear. Great site, and thanks.
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 13/14
• Reply •
makes a lot clear. Great site, and thanks.
• Reply •
Rocío García Luque • a month ago
Precious :)
• Reply •
Jerry Marshall • 2 months ago
great guide, thanks!!
• Reply •
pshinoj • 2 months ago
This is really useful for GitHub starters! Thanks
• Reply •
Rajesh Mule • 2 months ago
Hi, I have created an Android app based on this website that works offline and has all theawesomeness of the website. Hope it helps more people. Happy learning :)
https://play.google.com/store/...
2
• Reply •
Dmitriy Usakov • 2 months ago
one of the best tutorial for beginner! Thanks
• Reply •
Jiri Danecek • 2 months ago
I have read a lot of stuff about git but for the first time I know how to use it
• Reply •
DWisehart • 2 months ago
'git status' is another basic level command that would be good to list. Easier to rememberthan 'git commit dryrun'.
• Reply •
Uday • 2 months ago
Awesome, thanks a ton :)
• Reply •
saeed raeesmohammadi • 2 months ago
Thanks a lot!
• Reply •
Jinal Kothari • 2 months ago
Thanks a ton!! This is super helpful!!!!!!
• Reply •
Daniel García Páez • 2 months ago
The perfect guide!
• Reply •
Nicholas Lawson • 2 months ago
Just what I was looking for.
• Reply •
Deepak • 2 months ago
Indeed a simple, helpful & amazing guide!!Thanks for your efforts for putting up such a useful & concise tutorial
• Reply •
Bob • 2 months ago
Best guide ever, it now all makes sense thanks so much!
William • 2 months ago
Great guide!
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
Share ›
1/8/2015 git - the simple guide - no deep shit!
http://rogerdudler.github.io/git-guide/ 14/14
Load more comments
git guia prático sem complicação!73 comments • 2 years ago
Bruno Barcellos — Esse livro édistribuído gratuitamente através da licençaCreative Commons, logo não …
git ก าวแรกสสงเวยน5 comments • a month ago
Prapath Nui Suayroop — ขอบค ณครบคงต องอานอกหลาย ๆ ท แต เรมเขาใจมากขนกวาตอนอาน Text แลวละครบ
git 간편가이드 어렵지 않아요!1 comment • 2 years ago
d — ssssssss what a good site
git Der einfache Einstieg keinSchnickschnack!33 comments • 2 years ago
tk — Hat mir sehr geholfen. Danke!
ALSO ON GIT THE SIMPLE GUIDE
• Reply •
• Reply •
John Zhao • 2 months ago
Greatest guide for beginners!
• Reply •
Andrii Kuplevakhskyi • 2 months ago
Hello Roger,many thanks for such a guide! It seems to be very useful for newbies.I'd like to translate the guide into Ukrainian. I'll try yo play with the sources on GitHub todo it. We'll see how it goes.Please, let me know if you have any thoughts/objections.Cheers,
• Reply •
mahdi • 2 months ago
Thanks so much
WHAT'S THIS?
Subscribe Add Disqus to your sited Privacy
Share ›
Share ›
Share ›
Share ›