git config –global user.name "[name]"
-> sets author namegit config –global user.email "[email address]"
-> sets author email id
- Create a .gitignore file and define which files are not added to git
- Don't push vendors (f.e. composer or node-modules) to git
- Never
git add
,git commit
, orgit push
sensitive information to a remote repository (f.e. Passwords SSH keys, API keys, Credit card numbers), instead use enviroment variables (and gitignore them)
git init [repository name]
-> start new repositorygit clone [url]
-> obtain a repository from an existing URLgit remote -v
- if you want to double check, verifie the new remote URL
git init -b main
-> initializes the local directory as a Git repositorygit add .
-> adds the files in the local repository and stages them for commit. To unstage a file, usegit reset [file name]
git commit -m "[your commit message]"
-> commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use'git reset --soft HEAD~1'
and commit and add the file againgit remote add origin [remote url from GitHub]
-> sets the new remotegit remote -v
- if you want to double check, verifie the new remote URLgit push -u origin main
-> pushes the changes in your local repository up to the remote repository you specified as the origin
git remote -v
-> checking the current remote (forgit push
andgit pull
(orgit fetch
git merge
))git remote add [variable name] [remote server link]"
-> used to connect your local repo to the remote repo on GitHub
git status
-> show the working tree statusgit add
-> if git status was used before adds all untracked from working tree status to staginggit add [file]
-> adds a specific file to the staginggit add .
-> adds all files to the staging
git commit -m "[your commit message]"
-> records or snapshots the file permanently in the version history and add a comment to it. You can add a description also with just repeating the-m
flag and a messag is quotes, likegit commit -m "[your commit message] -m "[your commit description]"
git commit -a
-> automatically stages files that have been modified and deleted, but new files you have not told Git about are not affectedgit tag [commitID]
-> used to give tags to the specified commit
git push [origin, remote url or variable name] [branch]
-> sends the branch commits to your remote repositorygit push -u [origin, remote url or variable name] [branch]
-> you can set an upstream if your want to save typing. Upstream branches define the branch tracked on the remote repository by your local remote branch. Set your upstreamgit push -u [origin, remote url or variable name] [branch]
so you only need to typegit push
and it will automaticall push to the set upstream ([origin, remote url or variable name] [branch]
)git push –all
-> pushes all branches to your remote repository.
git pull [remote url]
-> pulls the copy of the current branch stored in the repos and merges it with the local repogit pull --rebase
-> replaces remote repo changes with the local staus.git pull --rebase
is more like thesvn update
command than a pure git pullgit config --global pull.rebase "true"
-> is a configuration command that autmatically does arebase
when ulling
git fetch [remote url or variable]
-> gets all data and branches from the remote repogit merge [branch]
-> merge the given local branch into your current local branchgit merge [branch variable]/[branch]
-> merge the given fetched remote branch into your current local branch
git branch -a
-> lists all the local branches in the current repositorygit branch [branch name]
-> creates a new branchgit checkout [branch name]
-> used to switch from one branch to anothergit checkout -b [branch name]
-> creates a new branch and also switches to itgit merge [branch name]
-> merges the specified branch’s history into the current branchgit branch -d [branch name]
-> deletes the local branchgit push origin --delete [branch name]
-> deletes the remote branch
git-diff
- shows changes between commits, commit and working treegit diff –staged
-> show comparison between staged changes and the latest commitgit diff [first branch] [second branch
] -> differences between the two branches given
git reset [file]
-> unstages the file, but it preserves the file contentsgit reset [commit]
-> undoes all the commits after the specified commit and preserves the changes locallygit reset –hard [commit]
-> discards all history (deletes/overwrites files if Git don't know about them) and goes back to the specified commit
git rm [file]
-> deletes the file from your working directory and stages the deletion
git log
-> used to list the version history for the current branchgit log –follow[file]
-> lists version history for a file, including the renaming of files alsogit show [commit]
-> shows the metadata and content changes of the specified commit