Table of contents
What is GIT?
It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to tracking changes in the source code, enabling multiple developers to work together on non-linear development.
Difference between Git and GitHub?
Git is a version control system that let us manage and keep track of source code history. GitHub is a cloud-based hosting service that let us manage Git repositories.
GIT Commands
To check git is installed or not
$ git --version
help command
The first command, every beginner must know is $ git help as it gives you all the below commands and their use
$ git help
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--super-prefix=<path>] [--config-env=<name>=<envvar>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
Setting up username and email
$ git config --global user.name "Sumedh Vasudev"
$ git config --global user.email "sumedh@gmail.com"
Check if username and email got added
$ git config --global user.name
$ git config --global user.email
Open the folder you want to push on to the GitHub in VS code or any other editor.
Then set your default terminal as GIT BASH. Also, create an account in GitHub and create a new repository.
Commands to push a folder onto GitHub
1. git init
This command is used to start a new repository.
$ git init
2. git status
This command shows the metadata and content changes of the specified commit.
$ git status
3. git add
This command adds one or more to the staging area. If you want all the files to be added into staging area, you can use dot or asterisk instead of typing all file names.
$ git add readme.md
$ git add readme.md file1.py
$ git add *
$ git add .
4. git commit
This command records or snapshots the file permanently in the version history.
-m is for adding a message. For example, "initial commit", "updated readme file" etc.
$ git commit -m "Type some meaningful message"
5. git log
This command is used to list all the commits made in current branch
$ git log
6. git branch
This command creates a new branch. Here, the branch name is "main".
$ git branch -M main
7. git remote
This command is used to connect your local repository to the remote server.
$ git remote add [variable name] [Remote Server Link]
You can get this remote server link from the new repository you created in GitHub.
8. git push
$ git push [variable name] main
This is it !! Now you can see all the files of your selected folder got pushed into your GitHub repository.
We also had many other useful commands like git pull, git merge, git checkout etc.
Conclusion
Learning Git and GitHub seems complicated in the beginning. But it becomes handy by knowing some basic git commands and their use. Hope this article added some value. Thank you for reading :)