Git Handbook |Free Code Camp

Go back

Setting up

Check git version

git --version

Setting config values

git config --global user.name "{Name}"

git config --global user.email "{[email protected]}"

git config --list

Help Command

git help config

git config --help

How to initialize a repository

git init inside the project folder or git init {projectName} to start a new projectName

What to do before the first commit

git status

If there are files/folders you don't want to track with git usetouch .gitignore inside the document {folderName} will ignore everything inside the folder and {file.*} will ignore any file that starts with file.

Adding files to the staging area

git add {filename|-A|.}

Removing files from the staging area

git reset .gitinore will remove the file from the staging area, if you want to remove all the files from stage use git reset

Making the first commit

git add -A

git commit -m "Initial Commit"

To see the commit you just have done type

git log

Cloning a remote repository

git clone {sshRepoDir} {whereToClone}

Viewing information about the remote repo

git remote -v

git branch -a

Pushing changes to the remote repository

git diff

git add -A

git status

git commit -m "{theCommitMessage}"

git pull origin main

git push origin master

Creating a branch for a feature or issue

git branch {newBranchName}

git checkout {newBranchName} to switch to the new branch

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam

Pushing branch to remote repository after committing

git push -u origin new-branch

To see all the branches git branch -a

Merging branch

git checkout main

git pull origin main

git branch --merged

git merge new-branch

git push origin main

Deleting a branch

git branch --merged

git branch -d new-branch

git branch -a

git push origin --delete new-branch

Back