https://github.com/alexb017/namerepo.git
[email protected]:alexb017/namerepo.git
...or create new repository on the command line
echo "# cmd" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/alexb017/namerepo.git
git push -u origin main
..or push an existing repository from the command line
git remote add origin https://github.com/alexb017/namerepo.git
git branch -M main
git push -u origin main
git remote set-url origin https://...
git remote set-url --push origin https://...
View the configured remotes with git remote -v
.
init
- Initialize a new Git repository.clone
- Create a local copy of the repository, including all of its history and branches.git clone <repo-link>
add
- Add the specified file(s) to the staging area, where they will be included in the next commit.git add index.html
commit
- Record the staged changes and any additional changes made since the last commit, along with a commit message describing the changes.git commit -m "Fix"
push
- This sends the local commits to the specified remote repository, updating the branch on the remote with the new commits.git push origin master
pull
- Retrieve the latest commits from the specified remote repository and merges them into the current branch.git pull origin main
branch
- Can be used to list the available branches in a repository, create a new branch, or delete an existing branch.git branch new-branch
checkout
- Allow you to switch to a different branch in the repository and make it the current working branch.git checkout main
merge
- Combines the changes from one branch into another branch, creating a new commit that reflects the merged changes.git merge branch-name
status
- Display current branch, any staged or unstaged changes, and any untracked files.git status
rebase
- Let's say you have made some changes on an "XYZ" branch that you want to incorporate into the "main" branch. You can use git rebase to reapply your changes on top of the main branche.
git checkout main
git pull
git checkout xyz
git rebase main
stash
- If you changes are not ready to commit but you want to work an a different branch, you can temporarily save your changes for later use and switch branches withour losing your progress.git stash
revert
- Let's say you have made a mistake in a previous commit and you need to undo it. You can use git revert to create a new commit that undoes the changes introduced by the previous commit. You can do this with commit hash, or usingHEAD~n..HEAD
, wheren
is the number of commits beforeHEAD
.git revert HEAD~n..HEAD
add .
- add all tracked(modified/deleted) filesadd -u
- add all tracked(modified/deleted) + untracked(added/modified) filesadd -A
- add all tracked(modified/deleted) + untracked(added/modified) files + stagedlog
- Shows the public commit history of your repository.git log
reflog
- Focuses on the history of branch and HEAD movements. Acts like an undo log for your local repository.git reflog
- Create a new branch
git checkout -b branch-name
- Check status
git status
- Add changes
git add .
- Add commit/save changes
git commit -m "message"
- Upload all changes to github
git push -u origin branch-name
- Bring any changes from main to
branch-name
, to not have conflicts (good habit)git pull origin main
- Open pull request on github, if everything is ok delete branch
git checkout main
- Get all the changes into main from github repo
git pull
- Delete branch
git branch -D branch-name
from local not github