DEV Community

Cover image for Everything you need to know about Git
Doraking
Doraking

Posted on

Everything you need to know about Git

User setting

Sets the name and email that will be attached to your commits and tags globally

git config --global user.name "<user_name>"
git config --global user.email "<email_address>"
Enter fullscreen mode Exit fullscreen mode

Create local repository

Initializes a new Git repository in your current directory, creating a .git folder

git init
Enter fullscreen mode Exit fullscreen mode

File staging

Adds a file named to the staging area, making it ready for committing

git add <file_name>
Enter fullscreen mode Exit fullscreen mode

Commit

Records or snapshots the staged changes in the repository, with a descriptive message

git commit -m "<commit_message>"
Enter fullscreen mode Exit fullscreen mode

Create branch

Creates a new branch named ( main, feature, etc)

git branch <branch_name>
Enter fullscreen mode Exit fullscreen mode

Switch branch

Switches to the specified branch name , updating the working directory to match

git checkout <branch_name>
Enter fullscreen mode Exit fullscreen mode

Add remote repository

Adds a new remote git repository (origin is often used) as shortname you can reference

git remote add <remote_repository_name> <https://github.com/example.git>
Enter fullscreen mode Exit fullscreen mode

Push

Uploads all local branch commits to the remote repository

git push <remote_repository_name> <branch_name>
Enter fullscreen mode Exit fullscreen mode

Pull

Fetches and integrates changes from the remote branch into your current branch

git pull <remote_repository_name> <branch_name>
Enter fullscreen mode Exit fullscreen mode

Merge

Merges the specified branch’s history into the current branch, combining changes

git merge <branch_name>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)