A handy guide to getting Started with git, with advanced content,;).
Thanks:@tfnico, @fhd and namics
Other languages中文版, Deutsch, español, français, Italiano, Nederlands , Português, русский, Türkçe,
?????? , Japanese , ???
If you have any flaws, please go to GitHub
Download git OSX version
Download git Windows edition
Download the git Linux version
Create a new warehouse
Create a new folder, open it, and then execute
To create a new git repository.
Check out the Warehouse
Execute the following command to create a cloned version of the local repository:
If this is the repository on the remote server, your command will look like this:
git clone [email protected]:/path/to/repository
Your local repository consists of three "trees" maintained by git. The first one is your working directory , it holds the actual file, the second is the buffer (Index),It's like a cache area, temporarily saves your changes, and finally the HEAD, which points to the result of your last commit.
Add and submit
You can schedule changes (add them to the cache) and use the following command:
git add <filename>
git add *
This is the first step in the Git basic workflow, using the following command to actually commit the changes:
Git commit-m "code submission Information"
Now, your changes have been submitted to HEAD, but not to your remote repository.
Your changes are now in the HEAD of the local repository. Execute the following command to commit the changes to the remote repository:
Git push Origin Master
You can replace master with any branch you want to push.
If you have not cloned an existing repository and want to connect your warehouse to a remote server, you can add it using the following command:
Git remote add Origin <server>
So you can push your changes to the server you added.
Branches are used to insulate the development of features. When you create a warehouse,master is "default." Develop on other branches, and then merge them onto the main branch when you are finished.
Create a branch called "feature_x" and Switch to the past:
Git checkout-b feature_x
Switch back to the main branch:
git checkout Master
Then delete the new branch:
Git branch-d feature_x
Unless you push the branch to the remote repository, the branch is not visible to others :
Git push Origin <branch>
Update and merge
To update your local repository to the latest changes, do the following:
To get (fetch) in your working directory and Merge (merge) remote changes.
To merge other branches into your current branch (for example, Master), execute:
git merge <branch>
In both cases, Git will try to automatically merge the changes. Unfortunately, automatic merging is not always successful, and can lead to conflicts (conflicts). This time you need to modify these files to human flesh merge these conflicts (conflicts) . After you've changed, you'll need to execute the following commands to mark them as merged successfully:
git add <filename>
Before merging the changes, you can also use the following commands to view:
git diff <source_branch> <target_branch>
It is recommended to create a label when the software is published. This is an old concept, also in SVN. You can execute the following command to create a label called 1.0.0 :
git tag 1.0.0 1b2e1d63ff
1b2e1d63ff is the first 10 characters of the commit ID you want to tag. Use the following command to get the commit ID:
You can also use the submission ID for fewer of the first few, as long as it is unique.
Replace local changes
If you do something wrong (naturally, this is not possible), you can replace the local change with the following command:
This command replaces the files in your working directory with the latest content in the HEAD. Changes that have been added to the cache, as well as new files, are unaffected.
If you want to discard all of your local changes and commits, you can get the latest version on the server and point your landlord branch to it:
Git fetch origin
git reset--hard origin/master
Built-in graphical git:
Color git output:
git config color.ui true
When the history is displayed, only one line of comment information is displayed:
git config format.pretty oneline
To add files interactively to the buffer:
Links and Resources
- GITX (L) (OSX, open source)
- Tower (OSX)
- Source Tree (OSX, free)
- GitHub for Mac (OS X, free)
- Gitbox (OSX)
Guides and Manuals
- Git Community Reference Book
- Professional Git
- Like git thinking
- GitHub Help
- A graphical Git guide
git Concise user Guide [go]