Git Basics
- echo "# repo_name" >> README.md
- Create basic markdown file with large heading.
- git init
-
Create empty Git repo in specified directory. Run with no arguments
to initialize the current directory as a git repository.
- git add .
-
Stage all changes for the next commit. Replace . with
a <file> to change a specific file.
- git commit -m "<message>"
- Commit the staged snapshot with commit message.
-
git remote add origin https://github.com/user-name/repo-name.git
- Create a new connection to a remote repo.
- git push -u origin master
- Push local branch to remote master repo.
- git config --global user.name "username"
-
Define author name to be used for all commits in current repo. Devs
commonly use --global flag to set config options for current user.
- git config --global user.email "email_id@example.com"
-
Define author email to be used for all commits in current repo. Devs
commonly use --global flag to set config options for current user.
- git pull
-
Fetch the specified remote’s copy of current branch and immediately
merge it into the local copy.
- git diff
-
Show unstaged changes between your index and working directory.
- git status
- List which files are staged, unstaged, and untracked.
- git log
-
Display the entire commit history using the default format. For
customization see additional options.
Git Branches
- git branch BranchName
- Create a new branch named BranchName without checkout.
- git checkout -b localBranchName
- Create and check out a new branch named localBranchName.
- git checkout BranchName
- checkout an existing branch.
- git push --set-upstream origin localBranchName
- Push local branch to remote repository.
- git fetch
- Fetch all of the branches from the repository.
- git branch -d localBranchName
- Delete a branch named localBranchName locally.
- git push origin --delete remoteBranchName
- Delete a branch named remoteBranchName from remote repository.
- git branch -m OLD-BRANCH-NAME NEW-BRANCH-NAME
- Rename branch name.
- git diff FIRST-BRANCH..SECOND-BRANCH
- Compare two branches.
- git branch -a
- check all available branches.