prompt> mkdir /path/to/repo:
prompt> cd /path/to/repo
prompt> git init
Initialized empty Git repository in /path/to/repo/.git/
prompt>
... create file(s) for first commit ...
prompt> git add .
prompt> git commit -m 'initial import'
Created initial commit bdebe5c: initial import.
1 files changed, 1 insertions(+), 0 deletions(-)
Note that the commit action only commits to your local repository.
Change one of my github repo name in two steps:
Firstly, cd to your local git directory, and find out what remote name(s) refer to that URL
$ git remote -v origin [email protected]:someuser/someproject.git
Then, set the new URL
$ git remote set-url origin [email protected]:someuser/newprojectname.git
or in older versions of git, you might need
$ git remote rm origin $ git remote add origin [email protected]:someuser/newprojectname.git
(origin is the most common remote name, but it might be called something else.)
But if there's lots of people who are working on your project, they will all need to do the above steps, and maybe you don't even know how to contact them all to tell them. That's what #1 is about.
Further reading:
- github - working with remotes
- Git Reference - remotes
- Git Book - Distributed Workflows
Footnotes:
1 The exact format of your URL depends on which protocol you are using, e.g.
- SSH = [email protected]:someuser/someproject.git
- HTTPS = https://[email protected]/someuser/someproject.git
- GIT = git://github.com/someuser/someproject.git
prompt>git push origin master
git commit --amend -m "New commit message"
If the commit you want to fix isn’t the most recent one:
-
git rebase --interactive $parent_of_flawed_commit
If you want to fix several flawed commits, pass the parent of the oldest one of them.
-
An editor will come up, with a list of all commits since the one you gave.
- Change
pick
toreword
(or on old versions of Git, toedit
) in front of any commits you want to fix. - Once you save, git will replay the listed commits.
- Change
-
Git will drop back you into your editor for every commit you said you want to reword, and into the shell for every commit you wanted to edit. If you’re in the shell:
- Change the commit in any way you like.
git commit --amend
git rebase --continue
Most of this sequence will be explained to you by the output of the various commands as you go. It’s very easy, you don’t need to memorise it – just remember that git rebase --interactive
lets you correct commits no matter how long ago they were.
Today, when I try to push some code to the remote, it told me the there is a permission issue, I finally fixed it by created a new key, add it to my git account and local account. Here is the process of adding to local
If you did not have a key, generate one according this https://help.github.com/articles/generating-ssh-keys
then add the key
$ ssh-add /c/Users/li/.ssh/key
Clone your repository
Create a new repository in a new directory via the following commands.
# Switch to home cd ~ # Make new directory mkdir repo02 # Switch to new directory cd ~/repo02 # Clone git clone ../remote-repository.git .