[How To] Tips for Git

This is a summary of tips that might be helpful in using Git.

1. Check detail of remote “origin” master

git remote -v

2. Set new remote origin

git remote set-url --add gituser@githost:user/project.git

For example:

git remote set-url --add git@git.tech-codes.com:tatung/m2-midterm-draft.git

3. Remove a remote, origin for example:

git remote rm origin

4. Add new remote, dest for example:

git remote add dest https://github.com/tatung/SoftModemLong.git

5. Set non-default port for git

For Mac or Linux, edit file ~/.ssh/config (can create a new one if not exists)

Host git.tech-codes.com
HostName git.tech-codes.com
Port 9722
User tatung

6. Add file in git

Add changed, new files which are not in .gitignore. This will not add removed files.

git add .

Add changed files which are not in .gitignore and removed files. This will not add untracked files.

git add -u

Add all of changes, removed, untracked. Same as git add .; git add -u

git add -A

7. List out all branches

For local

git branch

For local & remote

git branch -a

For remote only

git branch -r

8. Undo an add action

git reset HEAD <file>

or

git reset <file>

To undo all content of add action at once

git reset

Leave a Reply

Your email address will not be published. Required fields are marked *