GIT COMMANDS

GIT COMMANDS


Getting & Creating Projects :


1.git init - Initialize a local Git repository

2.git clone ssh://[email protected]/[username]/[repository-name].git - Create a local copy of a git repository


Basic Snapshotting :


1.git status - Check status

2.git add [file-name.txt] - Add a file to the staging area

3.git add -A - Add all new and changed files to the staging area

4.git commit -m "[commit message]" - Commit changes

5.git rm -r [file-name.txt] - Remove a file (or folder)


Branching & Merging :


1.git branch - List branches(the asterisk denotes the current branch)

2.git branch -a - List all branches(local and remote)

3.git branch [branch name] - Create a new branch

4.git branch -d [branch name] - Delete a branch

5.git push origin --delete [branch name] - Delete a remote branch

6.git checkout -b [branch name] - Create a new branch and switch to it

7.git checkout -b [branch name] origin/[branch name] - Clone a remote branch and switch to it

8.git branch -m [old branch name] [new branch name] - Rename a local branch

9.git checkout [branch name] - Switch to a branch

10.git checkout - - Switch to the branch last checked out

11.git checkout -- [file-name.txt] - discard changes to a file

12.git merge [branch name] - Merge a branch into the active branch

13.git merge [source branch] [target branch] - Merge a branch into the target branch

14.git stash - Stash changes in a dirty working directory

15.git stash clear - Remove all stashed entries


Sharing & Updating Projects :


1.git push origin [branch name] - Push a branch to your remote repository

2.git push -u origin [branch name] - Push changes to remote repository(and remember the branch)

3.git push - Push changes to remote repository(remembered branch)

4.git push origin --delete [branch name] - Delete a remote branch

5.git pull - Update local repository to the newest commit

6.git pull origin [branch name] - Pull changes from remote repository

7.git remote add origin ssh://[email protected]/[username]/[repository-name].git - Add a remote repository

8.git remote set-url origin ssh://[email protected]/[username]/[repository-name].git - Set a repository's origin branch to SSH


Inspection & Comparison :


1.git log - View changes

2.git log --summary - View changes(detailed)

3.git log --oneline - View changes(briefly)

4.git diff [source branch] [target branch] - Preview changes before merging


COMMIT HISTORY :


History of all commits

$ git log

Show changes over a time for a specific file

$ git log -p <file_name>

Who changed what and when in specific file

$ git blame <file_name>


UPDATE & PUBLISH :


List all recently configured remotes

$ git remote -v

Add a new remote repository

$ git remote add <name_here> <url>

Fetch all changes and merge with HEAD

$ git pull <remote> <branch>

Publish local changes on a remote

$ git push <remote> <branch>

Rebase your current HEAD onto <branch>

$ git rebase <branch>

Abort a rebase

$ git rebase --abort

Fetch all changes from <remote> but do not integrate with HEAD

$ git fetch <remote>

Continue a rebase

$ git rebase --continue


UNDOING CHANGES :


Undo all of the changes made in <commit>

$ git revert <commit>

Remove <file> from the staging area, but leave the WD unchanged.

$ git reset <file_name>


CONFIGURATION :


Define the author name to be used for all commits by the current user.

$ git config --global user.name <name>

Define the author email to be used for all commits by the current user.

$ git config --global user.email <email>

Open the global configuration file in a text editor for manual editing.

$ git config --global --edit





要查看或添加评论,请登录

社区洞察

其他会员也浏览了