Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
49 views

Git Class Note

The document provides an overview of basic Git commands for configuring a local repository, adding and committing files, viewing differences and history, branching and merging, and connecting to remote repositories. It explains how to check the Git version, configure user information, initialize and clone repositories, add and commit files, view the status and log, create and switch branches, merge branches, and push commits to a remote.

Uploaded by

ilkerdonmez1903
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Git Class Note

The document provides an overview of basic Git commands for configuring a local repository, adding and committing files, viewing differences and history, branching and merging, and connecting to remote repositories. It explains how to check the Git version, configure user information, initialize and clone repositories, add and commit files, view the status and log, create and switch branches, merge branches, and push commits to a remote.

Uploaded by

ilkerdonmez1903
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Git Class Note

Check if you have git in your computer

git --version

See the commands

git help

Configuration

git config --global user.name “<name>”


git config --global user.email “<email>”
git config --global core.editor “<text editor>”
git config --list
git config --global --edit

Associating text editors with Git


Using Sublime Text as your editor

Modify path to subl.exe according to your computer!

git config --global core.editor "'C:\Program Files\Sublime Text\subl.exe' -w"


git config --global core.editor "notepad"

Delete individual git config

git config --system --unset <key>


git config --global --unset user.name
git config --system --unset user.email
git config --system --list

Create a local repo

git init

1/5
Get the content of a remote repo

git clone <url>

See the status of your repo

git status

Stage files

git add <filename>


git add .

Record the current state


The git stash command takes your uncommitted changes (both staged and unstaged), saves them away
for later use, and then reverts them from your working copy.

At this point you're free to make changes, create new commits, switch branches, and perform any other
Git operations; then come back and re-apply your stash when you're ready.

git stash
git stash list
git stash pop
git stash apply <stash>
git stash clear
git stash drop <stash>

Commit

git commit
git commit -m “message”
git commit -am “message”
git commit --amend

See commit logs

2/5
git log
git log --oneline
git log --since=<date>
git log --since=2.weeks
git log --since="2008-01-15"
git log --since="2 years 1 day 3 minutes"
git log --until=<date>
git log -- <file>

See code differences

git diff

Clean

git rm
git rm --cached
git checkout

Branches
Rename the current branch

git branch -m <branch>

Rename the default branch

git config --global init.defaultBranch main

Create a new branch

git branch <branchname>

Switch to a branch

git checkout <branchname>

3/5
Create and switch to a branch

git checkout -b <branchname>

Delete a local branch

git branch -d <branchname>


git branch -D <branchname>

Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged
yet.

See branches

git branch
git branch -r
git branch -a

Merge two branches

git merge

Remote Ops
Connect to remote repo

git remote add origin <url>

Get the latest version

git fetch
git pull

Upload your commit

4/5
git push -u origin master/main
git push

Delete a remote branch

git push origin --delete <branchname>


git push origin :<branchname>

gitignore
A good documentation about gitignore

5/5

You might also like