Skip to content

Instantly share code, notes, and snippets.

@akash02-das
Last active March 16, 2022 10:35
Show Gist options
  • Select an option

  • Save akash02-das/e73ebca77fe971f7387f9d9a8e7407d5 to your computer and use it in GitHub Desktop.

Select an option

Save akash02-das/e73ebca77fe971f7387f9d9a8e7407d5 to your computer and use it in GitHub Desktop.
Git and Github

GIT INIT, CONFIGURE, STATUS AND CLONE

Git Initialize in working directory

git init

Clone any repository

git clone 

Configure git username and email

git config user.name "Akash Das"
git config user.email "[email protected]"
git config --list

check status

git status

GIT ADD AND RESET

Working directory to stage in local

stages all changes

git add --all

or

git add -A

git add . // stages new files and modifications(on the current directory and its subdirectories)

git add * // stages new files and modifications, without deletions (on the current directory and its subdirectories)

git add *.js // stages all .js or with any extension new files and modifications

git add -u // stages modifications and deletions, without new files

Stage to working directory in local

git reset // use 'git reset' to undo staged files to unstage


GIT COMMIT

Stage to local repogitory

git commit -m "write something about to commit"

Local repogitory to working directory

git reset HEAD~ // undo local repogitory to working directory

git reset --hard // Suppose, you have deleted any files from working directory and staged that deleted files and you want to back them in working directory then run this command


REMOVE FILES OR FOLDER

Remove any file from working directory using git

git rm // Remove the file and staged that deleted file

Remove any unstaged file from working directory using git (Forcefully)

git rm -f

Remove any folder from working directory using git (recursively)

git rm -r


BRANCHING WITH GIT (CHECKOUT, BRANCHING AND MERGING)

Show all branches

git branch

Create a new branch

git branch

Switch one branch to another branch

git checkout

Create a new branch and checkout to that new branch in one command

git checkout -b

Merging two branches

git merge

Merge with messages

git merge -m "message"


GIT PUSH, FETCH AND PULL

Local repogitory to remote repogitory

git push origin // git push command is used to upload local repository content to a remote repository

Remote repogitory to local repogitory

git fetch // git fetch really only downloads new data from a remote repository - but it doesn't integrate any of this new data into your working files. or git fetch --all // --all flag fetch all remotes.

Remote repogitory to working directory

git pull origin master/main // update your current HEAD branch with the latest changes from the remote server. This means that pull not only downloads new data; it also directly integrates it into your current working copy files.

*** Git Pull = Git Fetch + Git Merge

@akash02-das
Copy link
Author

git-and-github

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