Git Commands

Help command:
> git help


Initial empty Git repository (Create .git directory)
> git init

Set user name and email
> git config user.name "peter"
> git config user.email skybonep@gmail.com

List config variable
> git config -l


Add one file to repository (File must exist), it only let the repository knows the file, it has not committed yet. Every time you change the file content, you need to add again
> git add hello.txt

Add all files and subdirectory to Git repository
> git add .

Remove a file from repository (The file will be removed from the working directory), but it has not committed.
> git rm hello.txt

Rename a file, but it has not committed.
> git mv hello_old.txt hello_new.txt

Show the working status
> git status


Create branch
> git branch branchName

Switch between branches
> git checkout branchName


Commit to update the changes to the repository
> git commit -m "Initial content" --author="peter "
> git commit hello.txt
(You have to input a message about this commit action in the default text editor)
> git commit -a
Note: The above command is doing 2 things:
> git add .
> git commit



Show commit log
> git log

Show commit log from remote repository
> git log origin/master

Show commit details
(show last commit action)
> git show
([hash code] = hash code from git log command)
> git show [hash code]


Copy a new repository (the dir_old directory is the one containing .git, i.e. structure: dir_old/.git/)
> git clone dir_old dir_new

Add a new remote repository reference:
> git remote add origin "file:///c:\remote.git"

Show remote repository location:
> git remote -v

Send update to remote repository:
> git push origin

Get update from remote repostiory and merge:
> git pull origin master

See also:
- Install Git in Windows
- Set up Git Remote Repository with Dropbox

No comments:

Post a Comment