Git is a "distributed" VCS. You can run it
locally and disconnected from the Internet, and then "push" your changes
to a remote system (such as GitHub) .
It's a source code management system for software development.
A git repository contains, among other things, the following: A set of commit objects. A set of references to commit objects, called heads.
Here i am listing down some Git commands with brief text about what that command does.
It's a source code management system for software development.
A git repository contains, among other things, the following: A set of commit objects. A set of references to commit objects, called heads.
Here i am listing down some Git commands with brief text about what that command does.
1. Remove Git Tracking
$ rm -rf .git
2. Show Origin of the repository
$ git remote show origin
3. Adding files to Git
$ git add <filename>
$ git add *
$ rm -rf .git
2. Show Origin of the repository
$ git remote show origin
3. Adding files to Git
$ git add <filename>
$ git add *
4. Commit files
$ git commit -m "Commit message."
$ git commit -a
5.Status i.e list the files you've changed and those you still need to add or commit:
$ git status
6. Push i.e.send changes to the remote master branch of your remote repository:
$ git push origin master/dev/prod/branchName
7. Connect to a remote repository to be able to push to it:
$ git remote add origin <server>
8. List all currently configured remote repositories
$ git remote -v
9. List all the branches in your repository, and also tell you what branch you're currently in:
$ git branch
10. Create a new branch and switch to it:
$ git checkout -b <branchname>
11. Switch from one branch to another:
$ git checkout <branchname>
12. Delete the feature branch:
$ git branch -d <branchname> (not the remote branch!)
13. Push the branch to your remote repository, so others can use it:
$ git push origin <branchname>
14. Push all branches to your remote repository:
$ git push --all origin
15. Delete a branch on your remote repository:
$ git push origin :<branchname>
16. Fetch and merge changes on(from) the remote server to your working directory:
$ git pull
17. To merge a different branch into your active branch:
$ git merge <branchname>
18. View all the merge conflicts:
$ git diff
19. View the conflicts against the base file:
$ git diff --base <filename>
20. Preview changes, before merging:
$ git diff <sourcebranch> <targetbranch>
21. Tags. You can use tagging to mark a significant change set, such as a release:
$ git tag 1.0.0 <commitID>
22. Push all tags to remote repository:
$ git push --tags origin
23. Git add remote upstream
$ git remote add upstream https://github.com/nirmalyamondal/Drupal-Modules.git
24. If you want to see more information about a particular remote, you can use the git remote show [remote-name] command.
$ git remote show origin\
25. Undo local changes
If you mess up, you can replace the changes in your working tree with the last content in head:
Changes already added to the index, as well as new files, will be kept.
$ git checkout -- <filename>
26. Check the log of the Git commit
$ git log
27. Tell Git who you are
git config --global user.name "Nirmalya Mondal"
git config --global user.email nirmalya_email@domain.com
git config --list
28. Create a new local repository
$ git init
29. Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
$ git fetch origin
$ git reset --hard origin/master
30. Check out a repository
$ git clone /path/to/repository
$ git clone username@host:/path/to/repository
31. Removes all removed remote branches
$ git fetch --all --prune
32. Stashes the local changes, so they can’t be lost during a git pull.
$ git stash
33. Restores the changed files from the stash and tries to merge them.
$ git stash apply
34. Reverts an commit that is already committed and pushed.
$ git revert <hash>
35. Removes the given files from the remote repository
$ git rm <file1> <file2>
Don't be confused with pull and fetch command. In the simplest terms, git pull does a git fetch followed by a git merge.
Git's Workflow that i follow is like -
-------------
Forking the repository -> cloning it -> creating feature branches -> committing changes -> submitting pull requests.
-------------
Forking the repository -> cloning it -> creating feature branches -> committing changes -> submitting pull requests.
-------------
More commands to be added soon ...