Please enable JavaScript.
Coggle requires JavaScript to display documents.
GIT COMMANDS - Coggle Diagram
GIT COMMANDS
git log
-
-
to display a limited number of log entries use -n flag, where n is replaced with a number.
-
--pretty option will format the output in different one from the default. A few values are prebuilt such as: oneline, short, full, fuller. There is also a format value that lets you create your own format. Useful when generating output for machine parsing. format takes useful specifiers (to see them see the doc).
-
-
-
-
-S option takes a string and shows only those commits that changed the number of occurences of that string.
you can pass a path as a filter to output only commits that introduced a change to those files. Preceded by double dashes: --. It has to be the last option given to git log.
-
-
git remote
-
-v flag to show the URLs that git has stored for the shortname to be used when reading and writing to that remote.
-
git remote add <shortname> <url> -> explicitly adds a new remote to the git repo as a shortname-URL pair.
git remote show <remote> -> lists the URL for the remote repo, the tracking branch information and some other useful information.
-
git remote remove <remote_name> -> to remove a remote, all remote tracking branches and configuration settings associated with that remote are also deleted.
-
git config
variables can be stored in three different places: each level overrides values in the previous level.
[path]/etc/gitconfig file: -> contains values applied to every user on the system and all their repositories.
-
-
-
-
git config --list --show-origin -> to view all of your settings. --show-origin to see where they are coming from.
git config <option> <key> <value> -> to set a key to a specific value. Option can be local, global, system, ecc.
-
git commit
-
-v flag will put the diff of your change in the commit message inside the editor if no comment message is attached to the commit.
-
-a flag will skip the staging area by automatically staging every file that is already tracked before doing the commit.
--amend option will let you modify the last commit you did, if, for example, the commit message or some file needed some changes that you forgot to do in the first place.
So, to redo a commit, make the additional changes you forgot, stage them, and commit again with the --amend option.
This replaces the last commit, so no new commit is made.
-
git branch
git branch <branch_name> -> creates a new pointer to move around. It points to the commit you're currently on. Does not switch to that branch, that means that HEAD still points to the branch you were before this.
-
-
-
git branch -u <remote>/<branch> -> to set an already existing branch to a remote branch, thus creating a tracking branch. --set-upstream-to can substitute -u.
git add
git add <files> -> to begin tracking a new file, to stage a file, and to to mark merge-conflicted files as resolved.
takes a path for either a file or a dir; if it's a dir, the command adds all the files in that dir recursively.
-
git stages a file exactly as it is when git add is used. If the file is modified and not staged again before a commit, the staged version of the file is committed.
git fetch
git fetch <remote> -> looks up which server <remote> is, fetches any data from it that you don't yet have, and updates the local database, moving the remote tracking branches to their new, more up-to-date position.
if a new remote tracking branch is brought to the local repo with a fetch for the first time, there is no automatic local, editable copy of it.
only downloads data, doesn't automatically merge it with the project. Working dir isn't affected.
-
-
git status
used to check the status of files in the working directory. Either untracked, staged, modified... Also shows unmerged files after a merge conflict.
to check which branch you are on and, if the branch tracks a remote branch, if it has diverged or not from it (not sure, have to check).
-
.gitignore file
a file listing patterns to match files that git won't automatically add to the staging area or show as being untracked.
This way avoids committing files that shouldn't be committed such as build files, documentation files, ecc...
There can be more than one .gitignore file, it can be in a subdir. The rules apply only to the files under the dir where theyy are located.
git diff
-
-
git diff --staged or --cached -> what is staged that will go into next commit, compares staged changes to last commit.
git rm
-
to forcefully remove a file, that has local modifications that have not been committed, from the staging area a -f flag (force) is required.
to keep the file in the working tree but remove it from the staging area a --cached option is required. The file becomes untracked.
-
-
-
git checkout
-
git checkout <branch_name> -> to switch to an existing branch. Basically moves HEAD to point to <branch_name>.
-
-
git push
-
works only if the remote you are pushing to (upstream) gave you write access and if nobody has pushed in the meantime.
-
-
-
git mv
-
a shortcut for mv <old_name> <new_name>, git rm <old_name>, git add <new_name>
-
git merge
combines changes from one branch into another, integrating their histories.
when merging, checkout the branch you wish to branch into, and pass as a parameter of the merge command, the branch to merge in.
-
git pull
updates your current local branch by first downloading changes from the corresponding remote branch and then merging them into your local branch (git fetch + git merge). For it to work correctly, your current branch must be set up to track a remote branch—this means Git knows which remote branch to pull from. If no tracking relationship is configured, git pull will result in an error.