Basic github commands to get started.
-
create a new repository
- Best practices for names example: basic-github-commands
- use lower case.
- use dashes.
- create a .gitignore
- Best practices for names example: basic-github-commands
-
git clone
-
git add
[changes] orgit add .
- can be used with dot or not.
-
git status
-
git branch
- list local branches
-
git branch -D
[branch-name]- Force delete the specified branch, even if it has unmerged changes.
-
git branch -d
[branch-name]- Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes.
-
git branch -m
[branch-name]- rename branch
-
git branch -a
- list all remote branches.
-
git branch -vv
- check if your local branch is behind, ahead.
- Example:
- master 58ec21ac [origin/master] update changelog
- test-branch 58ec21ac update changelog
-
git checkout
[branch-name]- switch between branches
-
git checkout -b
[branch-name]- create new branch
-
git commit -m
"any-comment" -
git commit --allow-empty -m
"any-comment"- allow empty commits, no changes
-
git pull origin
[branch-name]- update local branch. ex: git pull origin master
-
git push origin
[branch-name]- used to publish local changes to a central repository.
-
git merge origin/master
- update local branch with master
-
git restore
[file-name] andgit restore .
- remove file or changes before
git add .
- remove file or changes before
-
git restore --staged
[file-name] andgit restore --staged .
- It will discard any local, uncommitted changes.
- Exemple: To remove changes after execute
git add .
-
git clean -f - d
[file-name]- delete untracked files
-
git log
- show commit logs
-
git reset –hard
[commit]- This command discards all history and goes back to the specified commit.
git reset --hard HEAD^
going back to the commit before HEAD.git reset --hard HEAD~2
going back two commits before HEAD.
-
git rebase -i HEAD~4
- HEAD means where you are working [current_branch].
- have 4 commits, but you haven’t pushed anything yet and you want to put everything into one commit.
- 4 is the number of commits, can be any number.
- all commits above: commit [commit-mumber] (origin/main, origin/HEAD)