A list of 50 frequently git questions with answers. Released under a CC-BY 4.0 license.
WARNING: not yet finished...
$ git --version
$ git init project
$ cd project
$ git config --global user.name "<your name>"
$ git config --global user.email "<your email>"
$ git config --global core.editor "nano -w"
The staging area is an intermediate storage for changes that will be part of the next commit.
$ git add <file>
$ git reset HEAD -- <file>
$ git commit -m "Commit message"
$ git config --list --show-origin
Add them to a local .gitignore
file
$ git rm --cached <file>
$ git reset HEAD~
$ nano <file>
$ git add <file>
$ git commit -c ORIG_HEAD
$ git commit --amend -m "New message"
$ git remote add <name> <url>
$ git diff HEAD -- <file>
$ git remote rename <old_name> <new_name>
$ git remote set-url <name> <new_url>
$ git push
$ git commit --author "Name Surname <email@address>" ...
$ git branch BRANCHNAME
$ git checkout BRANCHNAME
Tip:
$ git checkout -b BRANCHNAME
Will create and switch to the branch called BRANCHNAME
You can't unless you change the history
$ git remote -v
$ git tag -m '...' <commit>
$ git tag
In the global gitignore add a line like this
.gitignore
Or in the root of a dir add a line like this
folder_where_is_its_gitignore/.gitignore
$ git log @{u}..
$ git diff <branch-a> <branch-b> -- <file>
A single branch of another repository can be easily placed under a subdirectory retaining its history. For example:
git subtree add --prefix=rails git://github.com/rails/rails.git master
Create ~/.config/git/ignore
with a list of patterns.
git-rm
- Remove files from the working tree and from the index
rm
- remove files or directories
This is the default with git push
, not necessary to do anything.
You need to do that in the remote
$ git config --global alias.THEALIASED "WHAT_GIT_COMMAND_TO_ALIAS"
Note: If you want to alias a real command not a git command you need to use ! but your shell will try to find an event so you need to use a "!echo 'Test'"
Some blog post on freecodecamp
Briefly :
git fetch
is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn’t do any file transferring. It’s more like just checking to see if there are any changes available).
git pull
on the other hand does that AND brings (copy) those changes from the remote repository.
git log master HEAD~ --oneline | tail -1 | awk '{ print $1 }'
git shortlog -s -n | head -1
If you remove | head -1 you get all contributors