Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Last active March 17, 2023 09:45
Show Gist options
  • Save halitbatur/cf28d95f693b2b3608e11d8d137ce19a to your computer and use it in GitHub Desktop.
Save halitbatur/cf28d95f693b2b3608e11d8d137ce19a to your computer and use it in GitHub Desktop.
Git and Bash commands starter pack

Bash Commands

Making a directory

mkdir <directory-name>

Example

mkdir hello-world

Deleting an empty directory

rmdir <directory-name>

Changing directories

cd <directory-name>

Example

cd desktop/
cd hello-world/

A shorter way to perform the pervious example

cd desktop/hello-world/

Another helpful way to use cd is when you want to go back to the previous directory

cd ..

Creating a new file

touch <filename.extension>

Example

touch index.html
touch styles.css

A shorter way to perform the previous example

touch index.html styles.css

Lists directory contents

ls

Shows your current directory path

pwd

Git Commands

Initialize git repository in the current directory

git init .

Add all changes to staging

git add .

Add specific file to staging

git add file_name

Show difference in modified files not yet "added" to staging

git diff

Commit the "staged" files

git commit

Add comment to commit

git commit -m "modification note"

Show commit log

git log

Working with Branches

Show current branch

git branch

Creating a new branch

git branch new_branch_name

Switching to different branch

git checkout new_branch_name

A shorter way to perform the previous 2 commands

git checkout -b new_branch_name

Merging two branches

You want to be on the branch you want merged 'master', then merging branch_name into master

git merge branch_name

Working with a remote repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment