Create
Clone an existing repository
|
|
Clone an existing repository and all its sub-modules recursively
|
|
Create a new local repository
|
|
Configuration
Set the name attached to all your commits
|
|
Set the email attached to all your commits
|
|
Set colorization of command line output for all repos
|
|
Print set name (in current repository or globally)
|
|
Print set email (in current repository or globally)
|
|
Local Changes
Changed files in your working directory
|
|
Changes to tracked files
|
|
Add current changes in file to the next commit
|
|
Add all current changes to the next commit
|
|
Add some changes in
|
|
Rename file and add it to next commit
|
|
Delete file and add its deletion to next commit
|
|
Commit all local changes in tracked files
|
|
Commit previously staged changes
|
|
Change the last commit, Don‘t amend published commits!
|
|
Commit History
Show all commits, starting with newest
|
|
Show changes over time for a specific file
|
|
Some changes over time for a specific committer
|
|
Search (grep) commit message for the given string
|
|
Who changed what and when in
|
|
Store changes temporarily
|
|
Remove and apply stashed changes
|
|
Remove file from all previous commit but keep it locally
|
|
Branches & Tags
List all existing branches
|
|
Switch HEAD branch
|
|
Create a new branch based on your current HEAD
|
|
Create a new tracking branch based on a remote branch
|
|
Delete a local branch
|
|
Delete a remote branch
|
|
Rename a branch locally
|
|
Rename a branch on remote
|
|
Mark the current commit with a tag
|
|
Update & Publish
List all currently configured remotes
|
|
Show information about a remote
|
|
Add new remote repository, named
|
|
Delete a branch on the remote
|
|
Download all changes from
|
|
Download changes and directly merge/integrate into HEAD
|
|
Publish local changes on a remote
|
|
Track a remote repository
|
|
Publish your tags
|
|
Merge & Rebase
Merge
|
|
Rebase your current HEAD onto
|
|
Abort a rebase
|
|
Continue a rebase after resolving conflicts
|
|
Use your configured merge tool to solve conflicts
|
|
Use your editor to manually solve conflicts and ( after resolving) mark file as resolved
|
|
Undo
Discard all local changes in your working directory
|
|
Discard local changes in a specific file
|
|
Revert a commit (by producing a new commit with contrary changes)
|
|
Reset your HEAD pointer to a previous commit and discard all changes since then
|
|
Reset your HEAD pointer to a previous commit and preserve all changes as unstaged changes
|
|
Reset your HEAD pointer to a previous commit and preserve uncommitted local changes
|
|
Submodules
Make changes, commit and checkout submodule files just go the submodules directory and use git as usual.
List all currently configured submodules
|
|
or
|
|
Show information about a submodule
|
|
Add a new submodule
$ git submodule add -b <branch> --name <name> <repository-path-or-url>- add the
.gitmodulefile and submodule folder to the superproject index. - commit both files on the superproject
Git on the Server
|
|
Gitolite
|
|
https://github.com/sitaramc/gitolite
https://git-scm.com/book/zh/v1/%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git-Gitolite
http://williamherry.com/blog/2012/10/03/install-gitolite/
steps to install
First, prepare the ssh key:
- login to “git” on the server
- make sure ~/.ssh/authorized_keys is empty or non-existent
- make sure your ssh public key from your workstation has been copied as $HOME/YourName.pub
Next, install gitolite by running these commands:
|
|
Finally, setup gitolite with yourself as the administrator:
|
|
If the last command doesn’t run perhaps “bin” is not in your “PATH”. You can either add it, or just run:
|
|
If you get any other errors please refer to the online documentation whose URL was given at the top of this file.
adding users and repos
Do NOT add new repos or users manually on the server. Gitolite users, repos, and access rules are maintained by making changes to a special repo called “gitolite-admin” and pushing those changes to the server.
To administer your gitolite installation, start by doing this on your workstation (if you have not already done so):
|
|
NOTE: if you are asked for a password, something went wrong.. Go hit the link for the complete documentation earlier in this file.
Now if you “cd gitolite-admin”, you will see two subdirectories in it: “conf” and “keydir”.
To add new users alice, bob, and carol, obtain their public keys and add them to “keydir” as alice.pub, bob.pub, and carol.pub respectively.
To add a new repo “foo” and give different levels of access to these users, edit the file “conf/gitolite.conf” and add lines like this:
|
|
Once you have made these changes, do something like this:
|
|
When the push completes, gitolite will add the new users to ~/.ssh/authorized_keys on the server, as well as create a new, empty, repo called “foo”.
help for your users
Once a user has sent you their public key and you have added them as specified above and given them access, you have to tell them what URL to access their repos at. This is usually “git clone git@host:reponame”; see man git-clone for other forms.
NOTE: again, if they are asked for a password, something is wrong.
If they need to know what repos they have access to, they just have to run “ssh git@host info”.
access rule examples
Gitolite’s access rules are very powerful. The simplest use was already shown above. Here is a slightly more detailed example:
|
|
Here’s what these example rules say:
- alice can do anything to any branch or tag – create, push, delete, rewind/overwrite etc.
- bob can create or fast-forward push any branch whose name does not start with “master” and create any tag whose name does not start with “v”+digit.
- carol can create tags whose names start with “v”+digit.
- dave can clone/fetch.
Please see the main documentation linked above for all the gory details, as well as more features and examples.
groups
Gitolite allows you to group users or repos for convenience. Here’s an example that creates two groups of users:
|
|
Group lists accumulate. The following two lines have the same effect as the earlier definition of @staff above:
|
|
You can also use group names in other group names:
|
|
Finally, @all is a special group name that is often convenient to use if you really mean “all repos” or “all users”.
commands
Users can run certain commands remotely, using ssh. Running
|
|
prints a list of available commands.
The most commonly used command is “info”. All commands respond to a single argument of “-h” with suitable information.
If you have shell on the server, you have a lot more commands available to you; try running “gitolite help”.