See also: S3 Management Class for AWS with Python
Git Basics
Make sure Git is installed on your system. You can download it from https://git-scm.com/.
2. Configuring Git:
Set your username and email globally:
git config --global user.name "Your Name" git config --global user.email "[email protected]"
3. Initializing a Repository:
To start tracking a new project or existing code, navigate to your project’s directory and run:
git init
4. Checking Repository Status:
View the status of your changes:
git status
5. Adding Changes:
Add changes to the staging area:
git add filename
Add all changes:
git add .
6. Committing Changes:
Commit staged changes:
git commit -m "Your commit message"
7. Viewing Commit History:
View the commit history:
git log
8. Creating Branches:
Create a new branch:
git branch branchname
9. Switching Branches:
Switch to a branch:
git checkout branchname
Create and switch to a new branch:
git checkout -b newbranch
10. Merging Branches:
– Merge changes from one branch into another:
git merge branchname
11. Remote Repositories:
– Add a remote repository:
git remote add origin remote_url
- Push changes to a remote repository: ``` git push -u origin branchname ``` - Pull changes from a remote repository: ``` git pull origin branchname ```
12. Cloning a Repository:
– Clone a repository from a URL:
git clone repository_url
13. Ignoring Files:
– Create a file named .gitignore to specify files/directories to ignore.
14. Undoing Changes:
– Discard changes in working directory:
git checkout — filename
- Unstage changes: ``` git reset filename ```
15. Tagging Releases:
– Create a lightweight tag:
git tag tagname
- Create an annotated tag: ``` git tag -a tagname -m "Tag message" ```
This is a basic overview of Git commands. There’s much more to learn, but these commands should get you started. Always refer to the official Git documentation for more in-depth information.