- Published on
10 git commands you should know
- Authors
- Name
- Ali Sina Yousofi
10 git commands you should know
Since you are a bit familiar with git, here are 10 commands which you must know as a developer.
Here are the commands which we will look into:
git init git init
git clone git clone
git status git status
git log git log
git branch git branch
git checkout git checkout
git add git add
git commit git commit
git push git push
git stashgit stash
git init
This command is for starting a new repository.
git init [repository name]
example:
git init demo
# output: Initialized empty Git repository in E:/Old E Drive/open-source/demo/.git/
2. git clone
This command is like copying a file from Github to your local machine.
git clone [url]
example:
$ git clone https://github.com/AliSinaYOusofi/TimeTrack
Cloning into 'TimeTrack'...
remote: Enumerating objects: 43, done.
remote: Counting objects: 100% (43/43), done.
remote: Compressing objects: 100% (37/37), done.
remote: Total 43 (delta 2), reused 39 (delta 1), pack-reused 0
Receiving objects: 100% (43/43), 204.92 KiB | 52.00 KiB/s, done.
Resolving deltas: 100% (2/2), done.
3. git status
This command will list all the files which have to be commited.
git status
example:
$ git status
On branch first_blog
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: data/blog/make_your_project_open_source.mdx
Untracked files:
(use "git add <file>..." to include in what will be committed)
data/blog/git_techniques.mdx
data/blog/ten_git_commands_you_should_know.mdx
no changes added to commit (use "git add" and/or "git commit -a")
4. git log
This command will output a list of commits in reverse chronological order (most recent first).
git log
example:
commit 91a7ed71c36ab63e3153afe833e3796cb29f21ca (HEAD -> first_blog, origin/first_blog)
Author: HajiAli <senayousofiali@gmail.com>
Date: Sun Jul 28 08:31:18 2024 +0430
added: another blog
commit 97f730a1799c9a853350ce01727803077d1242b7
Author: HajiAli <senayousofiali@gmail.com>
Date: Fri Jun 7 20:19:18 2024 +0430
NOTE: press q to exit log history.
5. git branch
This command lists all the local branches in the current repository.
git branch
example:
$ git branch
* first_blog
main
``
### 5. git checkout
This command is used when moving from one branch to another branch.
```bash
git checkout [branch_name]
example:
git checkout main
Switched to branch 'main'
Your branch is behind 'origin/main' by 18 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
NOTE: the following command will create a new branch and swithes to that branch:
git checkout -b [branc_name]
7. git add
This command will add file to the stagin area.
git add [file_name]
example:
git add ./data/blog/git_techniques.mdx
warning: in the working copy of 'data/blog/git_techniques.mdx', CRLF will be replaced by LF the next time Git touches it
8. git commit
This command records the file permanently in the version history.
git commit -m [commit messages]
example:
git commit -m "added: some new blogs"
[master (root-commit) aff342] first commit
9 files changed, 200 insertions(+)
- git push This command sends the committed changes of master branch to your remote repository.
git push [a variable name] master
### 10. git stash ❤️
Firstly I love this command, it will temporarily stores all modified tracked files.
If you modified changes and don't want to commit those changes you can stash them.
```bash
git stash save
and to restore:
git stash pop
and to list all stashed files:
git stash list
🎉🎉🎉 Thats it folks 👏👏👏
If you know these commands, well you know git.
Thanks for reading 🙏🏻