Skip to content

Instantly share code, notes, and snippets.

@vheidari
Created May 28, 2021 12:05
Show Gist options
  • Save vheidari/18938e5de13601cce21c1a16ef332f67 to your computer and use it in GitHub Desktop.
Save vheidari/18938e5de13601cce21c1a16ef332f67 to your computer and use it in GitHub Desktop.
πŸ“Œ Git Quick Tips :
GIT INIT :
= Add new repositry in local machin
- `git init`
=======================================================
GIT ADD :
= Add files to git track them
- `git add .`
- `git add -A`
=? FAQ :
?? What actually do `git add` command ?
- quick answer - `git add` command, added all untracked files to git that git can track them.
this command prepare files to track with git before send a commit to repository.
=======================================================
GIT STATUS :
= Show git status for
- git status
<?> note : this command show some information about your current working branch status like untracked and tracked files and commit status
=======================================================
GIT RM :
= Remove a file from cached
- git rm --cached [file-name]
<?> note : sometimes after use `git add .` command to track files. needing to remove a file from cached list.
that's made with `git add .` . the above command help us to remove a file from cache list.
=======================================================
GIT REMOTE :
= Add new remote repository in to git
- `git remote add [project-name] [url]`
= Remove old remote repository from git
- `git remote remove [project-name]`
= Update exists remote repository url
- `git remote set-url [project-name] [url]`
= show list of remote repository
- `git remote -v`
- `git remote`
?= FAQ:
?? can i have multiple repository on a project ?
- quick answer yes - during a development a project you might have 2 or more remote repository
you can add all them to git remote then work with them like send push or pull
=======================================================
GIT PULL :
= Pull remote 'origin' repositry and merge it on local 'master' repository
- `git pull [remote-repositry] [local-repository]`
<?> note: origin is a name to remote repository you can change it name for ex : `remote-repo` or `github-master` or somthing else
= Pulling unrelated histories repository
- `git pull [remote-repository] [local-repository] --allow-unrelated-histories`
<?> note: --allow-unrelated-histories option help us to merging unrelated histories repository.
<?> note: if during pull command has this error `fata: refusing to marge unrelated histories` ,
this command help us to mergin and resolve problem.
=======================================================
GIT PUSH :
= Push a local [master] repository to remote [origin] repository for ex on gihub
- git push [remote-repository] [local-repository]
<?> note: after fire this command maybe git needed your username and password on remote repository
that you must insert your username and password to git that it update your remote repository
=======================================================
GIT BRANCH
= Show list of branch
- `git branch`
<?> note : this command show only local branch on your local git repositry
- `git brand -a`
<?> note : this command show list both [remote-branch] and [local-branch]
= Show current branch
- `git branch --show-current`
= Create new branch
- `git branch [branch-name]`
= Remove a branch
- `git branch -D [branch-name]`
= Switch to another exists branch
- `git checkout [branch-name]`
= Merge a branch on another brand
- `git merge [another-branch]`
<?> note : suppose you have 3 branch , 'master', 'dev1', 'dev1_hotfix', you change sometihng in 'dev1_hotfix' and now
you want merge 'dev1_hotfix' last change 'dev1'. `git merge dev1_hotfix` command help us to merge 'dev1_hotfix'
to 'dev1'.
<?> note : to use `git merge dev1_hotfix` frist of all you must switch to 'dev1' branch with `git checkout dev1` then
use `get merge dev1_hotfi`
<?> note : after run merge command you can remove another branch for ex: 'dev1_hotfix' with 'get brand -d dev1_hotfix' command.
?= FAQ:
?? why we create some branch on a project ?
- quick answer to add some features and fix some issuse. branchs on git allow us to create a full copy from main source code.
then it help us to change , fix and update it and after test merged it with main source code.
=======================================================
GIT LOG :
= Show last log commits on your repository
- `git log`
= Show the number of last log commits
- `git log -n 1`
- `git log -n 10`
= Get help
- `git log -help`
=======================================================
GIT DIFF :
= Show last changes between to commit
`git diff`
=======================================================
GIT SUBMODULE :
= Add submodule project in to own project :
- `git submodule add http://github.com/username/project-name.git`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment