Skip to content

Instantly share code, notes, and snippets.

@deepwilson
Last active April 14, 2023 09:38
Show Gist options
  • Save deepwilson/0f815695dad76d28494eb0a66fbec54b to your computer and use it in GitHub Desktop.
Save deepwilson/0f815695dad76d28494eb0a66fbec54b to your computer and use it in GitHub Desktop.

Git Branches:


# setting global Git Username and Email 
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
git config --list
# The command saves the values in the global configuration file, ~/.gitconfig
# If you want to use a different username or email address for a specific repository, run the git config command without the --global option from within the repository directory


# view all remote
git remote -v

# view local branches:
git branch 

# view remote branches:
git branch -r

# change remote origin
git remote set-url <remote_name> <remote_url> 
#git remote set-url origin https://git-repo/new-repository.git
#git remote set-url upstream https://git-repo/new-repository.git

# view all local and remote branches:
git branch -a

# switch branch
git checkout <existing_branch>

# create new branch
git checkout -b <new_branch>

# push to branch
git push --set-upstream origin <your branch name>


# List all files in <branch>
git checkout <branch>
git ls-files

# once you switch to local branch then:
git pull origin "branchname" #this pulls all content(files/folders) from remote


#display all commit s with id
git log









Merge feature branch to main branch

# Switch to the main branch
git checkout main
# Merge the current branch to the main branch and squash the changes into a single commit
git merge --squash <branch-name>
# Review and stage the changes
git add .
# Commit the changes with a meaningful commit message
git commit -m "Merge <branch-name> to main"
# Push the merged changes to the remote repository
git push origin main

rules for git ignore


Rules for git ignore

To git ignore a folder: https://stackoverflow.com/a/28346487/7677793 create the ".gitignore" file with the contents:

*
!.gitignore

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